【问题标题】:how to pass the value of checkboxes as an array from view to controller in laravel 4如何将复选框的值作为数组从视图传递到laravel 4中的控制器
【发布时间】:2015-04-06 21:16:39
【问题描述】:

我想知道如何将多个复选框的值作为数组从我的视图传递给控制器​​。 这是我的代码:

我的看法:

@extends('layouts.master')

@section('content')

<?php
    $count = 1;
?>

{{ Form::open(array('method' => 'POST', 'action' => array('createQuizController@addQuestion'), 'id' => 'add_question')) }}

<div class="col-lg-10 col-lg-offset-1">
    <div class="table-responsive" id="question_table">
        <table class="table table-bordered table-striped">
            <thead>
            <tr>
                <th>ردیف</th>
                <th>عنوان سوال</th>
                <th></th>
            </tr>
            </thead>

            <tbody>
            @foreach ($result as $quiz)
                <tr>
                    <td align="center" width="100px">
                        <?php echo $count++; ?>
                    </td>
                    <td align="center" width="200px">{{ $quiz->title }}</td>
                    <td align="center" width="200px"><input type="checkbox" name="select_question[]" id="counter[]" value="{{ $quiz->lesson_id }}"></td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
{{ Form::submit('افزودن', ['class' => 'btn btn-primary']) }}

{{ Form::close() }}

<input type="text" id="count-checked" name="count-checked">

@stop

我想发布复选框的值; $quiz-&gt;lesson_id 作为我的控制器方法 addQuestion 的数组。

【问题讨论】:

    标签: php arrays checkbox laravel-4


    【解决方案1】:

    你快到了。我相信以下构造会为您生成数组,其中每个复选框都设置了正确的 ID。

    <input type="checkbox" name="select_question[{{ $quiz->lesson_id }}]" id="counter_{{ $quiz->lesson_id }}">
    

    【讨论】:

      猜你喜欢
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 2017-05-25
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多