Php 如何制作一个表单按钮来输入多个名称和值

Php 如何制作一个表单按钮来输入多个名称和值,php,sql,database,laravel,Php,Sql,Database,Laravel,我想做一个有按钮的表单 当我单击按钮时,将存储不同的输入,例如: 这是用于排队系统的, 如果我点击部门按钮并提交表单,它将自动存储部门->姓名、部门->信函和部门->编号 我有一个department和queue数据库表,它已经有了名称、字母和数字。以队列形式。我想从department中进行选择,如果我为department选择某个按钮,只需选择该按钮,它就会自动将其部门名称字母和编号存储到队列表中 ```<div class="btn-group-toggle" data-toggle

我想做一个有按钮的表单

当我单击按钮时,将存储不同的输入,例如: 这是用于排队系统的, 如果我点击部门按钮并提交表单,它将自动存储部门->姓名、部门->信函和部门->编号

我有一个department和queue数据库表,它已经有了名称、字母和数字。以队列形式。我想从department中进行选择,如果我为department选择某个按钮,只需选择该按钮,它就会自动将其部门名称字母和编号存储到队列表中

```<div class="btn-group-toggle" data-toggle="buttons">

    @foreach ($departments as $department)
        <label class="btn btn-secondary btn-lg w-25">
            <input type="radio" name="department" value="{{ $department->name}}" sr-only required> 
            {{ $department->name}}
        </label>
        <input type="hidden" name="letter" value="{{$department->letter}}">
        <input type="hidden" name="number" value="{{$department->number}}">
    @endforeach

</div>


@if ($errors->has('department'))
    <span class="invalid-feedback" role="alert">
        <strong>{{ $errors->first('department') }}</strong>
    </span>
@endif
</div>```
```
@foreach($部门作为$部门)
{{$department->name}
@endforeach
@如果($errors->has('department'))
{{$errors->first('department')}
@恩迪夫
```

您可以对多个值使用数组,这意味着您的
名称
属性名称将类似于
部门[]
&
字母[]
&
编号[]
。还非常推荐使用具有多个值的复选框。根据要求,您的代码如下所示:

<div class="btn-group-toggle" data-toggle="buttons">

    @foreach ($departments as $department)
        <label class="btn btn-secondary btn-lg w-25">
            <input type="checkbox" name="department[]" value="{{ $department->name}}" sr-only required> 
            {{ $department->name}}
        </label>
        <input type="hidden" name="letter[]" value="{{$department->letter}}">
        <input type="hidden" name="number[]" value="{{$department->number}}">
    @endforeach

</div>


@if ($errors->has('department'))
    <span class="invalid-feedback" role="alert">
        <strong>{{ $errors->first('department') }}</strong>
    </span>
@endif
</div>

@foreach($部门作为$部门)
{{$department->name}
@endforeach
@如果($errors->has('department'))
{{$errors->first('department')}
@恩迪夫

您可以对多个值使用数组,这意味着您的
名称
属性名称将类似于
部门[]
&
字母[]
&
编号[]
。还非常推荐使用具有多个值的复选框。根据要求,您的代码如下所示:

<div class="btn-group-toggle" data-toggle="buttons">

    @foreach ($departments as $department)
        <label class="btn btn-secondary btn-lg w-25">
            <input type="checkbox" name="department[]" value="{{ $department->name}}" sr-only required> 
            {{ $department->name}}
        </label>
        <input type="hidden" name="letter[]" value="{{$department->letter}}">
        <input type="hidden" name="number[]" value="{{$department->number}}">
    @endforeach

</div>


@if ($errors->has('department'))
    <span class="invalid-feedback" role="alert">
        <strong>{{ $errors->first('department') }}</strong>
    </span>
@endif
</div>

@foreach($部门作为$部门)
{{$department->name}
@endforeach
@如果($errors->has('department'))
{{$errors->first('department')}
@恩迪夫

我试图复制粘贴代码,但我有一些错误。我有一个department和queue数据库表,它已经有了名称、字母和数字。以队列形式。我想从部门中进行选择,如果我为部门选择某个按钮,它将自动将其部门名称字母和编号存储到队列表中,只需选择我们不了解的按钮…在队列表单中。。。如果你也能描述/展示你的桌子就更好了。而且,您给定的代码不完整。我们至少应该看到要检查的提交部分。@nnn这是我的队列datatables@nnn这是我的队列datatables$table->bigIncrements('id')$表->整数('snumber')$表->字符串('name')$表->字符串('email')$表->字符串('department')$表->字符串(“事务”)$表->字符串('字母')$表->整数('number')$表->字符串('备注')$表->字符串('called')$表->时间戳();这是我的部门datatable$table->bigIncrements('id')$表->字符串('name')$表->字符串('字母')$表->整数('number')$表->时间戳();队列的字母和数字值基于所选部门抱歉,太麻烦了。我尝试复制粘贴代码,但我有一些错误。我有一个department和queue数据库表,它已经有了名称、字母和数字。以队列形式。我想从部门中进行选择,如果我为部门选择某个按钮,它将自动将其部门名称字母和编号存储到队列表中,只需选择我们不了解的按钮…在队列表单中。。。如果你也能描述/展示你的桌子就更好了。而且,您给定的代码不完整。我们至少应该看到要检查的提交部分。@nnn这是我的队列datatables@nnn这是我的队列datatables$table->bigIncrements('id')$表->整数('snumber')$表->字符串('name')$表->字符串('email')$表->字符串('department')$表->字符串(“事务”)$表->字符串('字母')$表->整数('number')$表->字符串('备注')$表->字符串('called')$表->时间戳();这是我的部门datatable$table->bigIncrements('id')$表->字符串('name')$表->字符串('字母')$表->整数('number')$表->时间戳();队列的字母和数字值基于所选的部门抱歉,太乱了