Kaustubh
2 years ago
3467
10
Laravel

How to pass Checkbox value 0 if not checked and 1 if checked using array.

Posted 2 years ago by Kaustubh

Here its my HTML form

<form action="{{ url('NewPer') }}" method="post" class="formPermission">
{{ csrf_field() }}

@foreach($perList2 as $li)
    <div class="row">
      <div class="col-sm-4">{{ $li->p_Oname }}</div>
      <div class="col-sm-2"><input type="hidden" name="view[]" value="off"><input name="view[]" type="checkbox" value="on"></div>
      <div class="col-sm-2"><input type="hidden" name="add[]" value="off"><input name="add[]" type="checkbox" value="on"></div>
      <div class="col-sm-2"><input type="hidden" name="update[]" value="off"><input name="update[]" type="checkbox" value="on"></div>
      <div class="col-sm-2"><input type="hidden" name="delete[]" value="off"><input name="delete[]" type="checkbox" value="on"></div>
      
    </div><br>
@endforeach
    <div><input type="submit" class="btn btn-success pull-left" name="submit" value="Save"></div>
</form>

After Post It is taking hidden input if checkbox is checked

array:8 [▼
  "_token" => "2jLsqtIk80XlMyvcO0FrzLW4NqtTQDtywQ9bnoNe"
  "view" => array:6 [▼
    0 => "off"   ------------------->Hidden Input
    1 => "on"
    2 => "off"   ------------------->Hidden Input
    3 => "on"
    4 => "off"   ------------------->Hidden Input
    5 => "on"
  ]
  "add" => array:3 [▶]
  "update" => array:3 [▶]
  "delete" => array:3 [▶]
  "submit" => "Save"
]

Please sign in or create an account to participate in this conversation.