如何在Laravel 5中获取复选框数组的值? [英] How to get values of checkbox array in Laravel 5?

查看:70
本文介绍了如何在Laravel 5中获取复选框数组的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javascript创建了表单复选框:

I created checkboxes in form using javascript:

<input type="checkbox" name="is_ok[]" />
<input type="checkbox" name="is_ok[]" />
<input type="checkbox" name="is_ok[]" />

当我选中第一和第三复选框并提交表格时,Input::get("is_ok")返回我:

When I check 1st and 3rd checkbox and submit the form, Input::get("is_ok") returns me:

['on', 'on']

有什么方法可以获取['on', null, 'on']['on', 'off', 'on']的价值?

Is there any way to get value as ['on', null, 'on'] or ['on', 'off', 'on']?

提前谢谢.

推荐答案

嘿,您为应用程序中的user_id, product_id etc之类的复选框分配了一些值.

Hey assign some values to checkboxes like user_id, product_id etc what ever in your application.

例如查看

<input type="checkbox" name="is_ok[]" value="1" />
<input type="checkbox" name="is_ok[]" value="2" />
<input type="checkbox" name="is_ok[]" value="3" />

例如控制器

<?php
    if(isset($_POST['is_ok'])){
        if (is_array($_POST['is_ok'])) {
             foreach($_POST['is_ok'] as $value){
                echo $value;
             }
          } else {
            $value = $_POST['is_ok'];
            echo $value;
       }
   }
?>

您将获得所选复选框的数组.

You will get array of selected checkbox.

希望有帮助.

这篇关于如何在Laravel 5中获取复选框数组的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆