Added unchecked checkbox workaround

This commit is contained in:
Miguel Nogueira 2020-08-31 18:32:08 +01:00
parent ba3a139d1c
commit faa3a65e2b
2 changed files with 5 additions and 2 deletions

View File

@ -45,7 +45,10 @@
<form name="settings" id="settings" method="post" action="{{route('saveSettings')}}">
@foreach($options as $option)
<div class="form-group form-check">
<input type="checkbox" name="{{$option->option_name}}" id="{{$option->option_name}}" class="form-check-input" {{ ($option->option_value == 1) ? 'checked' : '' }}>
<!-- Unchecked checkbox hack: This only works for serverside languages that process the last duplicate element, since the browser sends both the hidden and checkbox values. -->
<!-- This "hack" is necessary because browsers don't send, by default, unchecked checkboxes to the server, so we would have no way to know if X checkbox was unchecked. -->
<input type="hidden" name="{{$option->option_name}}" value="0">
<input type="checkbox" name="{{$option->option_name}}" value="1" id="{{$option->option_name}}" class="form-check-input" {{ ($option->option_value == 1) ? 'checked' : '' }}>
<label for="{{$option->option_name}}">{{$option->friendly_name}}</label>
</div>
@endforeach

View File

@ -162,7 +162,7 @@ Route::group(['middleware' => ['auth', 'forcelogout', '2fa']], function(){
Route::get('settings', 'OptionsController@index')
->name('showSettings');
Route::get('settings/save', 'OptionsController@saveSettings')
Route::post('settings/save', 'OptionsController@saveSettings')
->name('saveSettings');
Route::post('players/ban/{user}', 'BanController@insert')