php - 带有自由文本的选择选项的 PHP 旧值
问题描述
我有一个带有自由文本选项的选择选项,例如带有自由文本的 单选按钮
<div class="form-body">
<div class="form-group row @error('warna') has-error @enderror">
<label class="control-label text-right col-md-3">Buta Warna</label>
<div class="col-md-3">
<input type=radio id="warna1" name="warna" value="Negatif"
@if(isset($mcu_form_tensi)){{ $mcu_form_tensi->warna == 'Negatif' ? 'checked' : ''}}@endif>
Negatif</option><br>
<input type=radio id="warna2" name="warna" value="Partial"
@if(isset($mcu_form_tensi)){{ $mcu_form_tensi->warna == 'Partial' ? 'checked' : ''}}@endif>
Partial</option><br>
<input type=radio id="warna3" name="warna" value="Total"
@if(isset($mcu_form_tensi)){{ $mcu_form_tensi->warna == 'Total' ? 'checked' : ''}}@endif>
Total</option><br>
<input type=radio id="warna4" name="warna" value="Other" @if(isset($mcu_form_tensi))
@if($mcu_form_tensi->warna != 'Negatif' && $mcu_form_tensi->warna != 'Partial' &&
$mcu_form_tensi->warna != 'Total') checked @endif @endif> Other</option><br>
<input id="txt_warna_other" type="text" name="warna" placeholder=""
class="form-control @error('warna') has-error @enderror" autocomplete="warna"
value="@if(isset($mcu_form_tensi)) {{ $mcu_form_tensi->warna }} @endif"
@if(isset($mcu_form_tensi)) @if($mcu_form_tensi->warna == 'Negatif' ||
$mcu_form_tensi->warna == 'Partial' || $mcu_form_tensi->warna == 'Total') readonly @endif
@endif>
@error('warna')
<div class="text-danger">
<small>{{ $message }}</small>
</div>
@enderror
</div>
</div>
</div>
如果新记录的验证失败,我将无法保留旧值。它不断恢复为无选择,因此用户必须再次选择。请帮助,这样用户就不需要再次输入,他们只输入那些无效的输入。
解决方案
这是我的工作代码
<div class="form-group row @error('warna') has-error @enderror">
<label class="control-label text-right col-md-3">Buta Warna</label>
<div class="col-md-3">
<input type=radio id="warna1" name="warna" value="Negatif"
@if(isset($mcu_form_tensi)){{ $mcu_form_tensi->warna == 'Negatif' ? 'checked' : ''}}
@elseif(old('warna')=='Negatif' ) checked @endif>
Negatif</option><br>
<input type=radio id="warna2" name="warna" value="Partial"
@if(isset($mcu_form_tensi)){{ $mcu_form_tensi->warna == 'Partial' ? 'checked' : ''}}
@elseif(old('warna')=='Partial' ) checked @endif>
Partial</option><br>
<input type=radio id="warna3" name="warna" value="Total"
@if(isset($mcu_form_tensi)){{ $mcu_form_tensi->warna == 'Total' ? 'checked' : ''}}
@elseif(old('warna')=='Total' ) checked @endif>
Total</option><br>
<input type=radio id="warna4" name="warna" value="Other" @if(isset($mcu_form_tensi))
@if($mcu_form_tensi->warna != 'Negatif' && $mcu_form_tensi->warna != 'Partial' &&
$mcu_form_tensi->warna != 'Total') checked @endif @elseif(old('warna') != 'Negatif' &&
old('warna') != 'Partial' && old('warna') != 'Total')
checked @endif> Other</option><br>
<input id="txt_warna_other" type="text" name="warna" placeholder=""
class="form-control @error('warna') has-error @enderror" autocomplete="warna"
value="@if(isset($mcu_form_tensi)) {{ $mcu_form_tensi->warna }} @else {{old('warna')}}@endif"
@if(isset($mcu_form_tensi)) @if($mcu_form_tensi->warna == 'Negatif' ||
$mcu_form_tensi->warna == 'Partial' || $mcu_form_tensi->warna == 'Total') readonly @endif
@endif>
@error('warna')
<div class="text-danger">
<small>{{ $message }}</small>
</div>
@enderror
</div>
</div>
希望这对其他人也有帮助
推荐阅读
- html - 如何相对于上部图像定位另一个图像
- python - Pandas - 多轴上 groupby() 上的 cumsum()
- javascript - 在 Odoo 12 的向导中单击取消后如何返回主页?
- python - 创建一个从用户获取输入并检查负值的 while 循环
- typescript - 我无法理解如何用 typerscript 语言定义 xpath 的语法
- python - 改组大型内存映射的numpy数组
- python - Python Openpyxl - 在 write_only 电子表格中添加列
- python - 如何从列表 [100x2] 创建列表 [10x2]
- node.js - 使用 express session 跨不同路由共享信息
- sql - 替换函数需要 3 个参数