'Hidden checkbox is still Submitted When i have the checkbox checked
<td><input type="checkbox" name="level_one[{{$loop->index}}][]" class="check" value="1"><input type="hidden" name="level_one[{{$loop->index}}][]" class="check" value="0"></td>
<td><input type="checkbox" name="level_two[{{$loop->index}}][]" class="check" value="1"><input type="hidden" name="level_two[{{$loop->index}}][]" class="check" value="0"></td>
<td><input type="checkbox" name="level_three[{{$loop->index}}][]" class="check" value="1"><input type="hidden" name="level_three[{{$loop->index}}][]" class="check" value="0"></td>
<td><input type="checkbox" name="level_four[{{$loop->index}}][]" class=" check" value="1"><input type="hidden" name="level_four[{{$loop->index}}][]" class="check" value="0"></td>
<td><input type="checkbox" name="level_five[{{$loop->index}}][]" class=" check" value="1"><input type="hidden" name="level_five[{{$loop->index}}][]" class="check" value="0"></td>
<td><input type="checkbox" name="level_six[{{$loop->index}}][]" class="check" value="1"><input type="hidden" name="level_six[{{$loop->index}}][]" class="check" value="0"></td>
<td><input type="checkbox" name="level_seven[{{$loop->index}}][]" class="check" value="1"><input type="hidden" name="level_seven[{{$loop->index}}][]" class="check" value="0"></td>
I have an issue with the checkbox both checkbox and hidden are both submitted when i have the checkbox checked how can i prevent this from happening
Solution 1:[1]
I have found an easy way to post this though the above various sources claims it works but for me it didn't work the hidden input filed is getting posted regardless but working well when the checkbox is not ticked i changed my form to this
<td><input type="checkbox" name="level_one[{{$loop->index}}]" class="check" value="1"></td>
<td><input type="checkbox" name="level_two[{{$loop->index}}]" class="check" value="1"></td>
<td><input type="checkbox" name="level_three[{{$loop->index}}]" class="check" value="1"></td>
<td><input type="checkbox" name="level_four[{{$loop->index}}]" class=" check" value="1"></td>
<td><input type="checkbox" name="level_five[{{$loop->index}}]" class=" check" value="1"></td>
<td><input type="checkbox" name="level_six[{{$loop->index}}]" class="check" value="1"></td>
<td><input type="checkbox" name="level_seven[{{$loop->index}}]" class="check" value="1"></td>
<td><input type="checkbox" name="level_eight[{{$loop->index}}]" class=" check" value="1"></td>
<td><input type="checkbox" name="level_nine[{{$loop->index}}]" class="check" value="1"></td>
<td><input type="checkbox" name="level_ten[{{$loop->index}}]" class="check" value="1"></td>
and in the controller i used this
$data[] = array(
'user_id' =>$request->input('user_id'),
'price_list'=>$request->input('price_list')[$i],
'level_one'=>$request->input('level_one')[$i]??'0',
'level_two'=>$request->input('level_two')[$i]??'0',
'level_three'=>$request->input('level_three')[$i]??'0',
'level_four'=>$request->input('level_four')[$i]??'0',
'level_five'=>$request->input('level_five')[$i]??'0',
'level_six'=>$request->input('level_six')[$i]??'0',
'level_seven'=>$request->input('level_seven')[$i]??0,
'level_eight'=>$request->input('level_eight')[$i]??0,
'level_nine'=>$request->input('level_nine')[$i]??0,
'level_ten'=>$request->input('level_ten')[$i]??'0',
'country_id'=> implode(',', $request->input('country_id',[])[$i]??[]),
'created_at'=>Carbon::now(),
);
so if the the value is empty i used ternary operator to assign it a zero as i intended
Solution 2:[2]
You Have to remove name from hidden field after that this is working fine....
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mannu254 |
| Solution 2 | Surbhi Khapra |
