Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在通过使用laravel的更新请求进行验证后,如何在复选框中维护旧的输入值?_Php_Laravel_Validation_Input_Checkbox - Fatal编程技术网

Php 在通过使用laravel的更新请求进行验证后,如何在复选框中维护旧的输入值?

Php 在通过使用laravel的更新请求进行验证后,如何在复选框中维护旧的输入值?,php,laravel,validation,input,checkbox,Php,Laravel,Validation,Input,Checkbox,当我打开编辑页面时,它应该具有来自数据库的值,当我更改该值时,如果Validation失败,我需要{old('input')}}值来保持。 代码如下: <input type="checkbox" id="show_in_website" name="show_in_website" @if($data->show_in_website=='1') checked @endif>Show in Website

当我打开编辑页面时,它应该具有来自数据库的值,当我更改该值时,如果Validation失败,我需要{old('input')}}值来保持。 代码如下:

<input type="checkbox" id="show_in_website" name="show_in_website"  @if($data->show_in_website=='1') checked @endif>Show in Website
       
show_in_website=='1')选中@endif>show in website

您可以使用
old()
helper方法。
old()
helper方法支持在验证失败时检索任何旧表单值。此外,它还允许在empty/null上传递默认值,这意味着我们可以在最初调用编辑页面时将数据库中的值作为默认值传递

<input type="checkbox" id="show_in_website" name="show_in_website" {{ old('show_in_website', $data->show_in_website) ? 'checked' : '' }}> Show in Website

您可以使用
old()
helper方法执行此操作。
old()
helper方法支持在验证失败时检索任何旧表单值。此外,它还允许在empty/null上传递默认值,这意味着我们可以在最初调用编辑页面时将数据库中的值作为默认值传递

<input type="checkbox" id="show_in_website" name="show_in_website" {{ old('show_in_website', $data->show_in_website) ? 'checked' : '' }}> Show in Website

代码不起作用吗?我想你可能想把
值=“{{{$data->show_in_website}}}”
设置为一个特定的东西,而不是任何
show_in_website
设置的东西。你的意思是你想让它保持在提交表单时的状态吗,如果验证失败了呢?当我打开编辑页面时,它应该有来自数据库的值,当我更改值时,如果验证失败,我需要{old('input')}}值persist@RoshJ只需将
value=“1”
添加到您的输入中,您就会发现该代码不起作用了吗,不是答案我想你可能想将
值=“{{{$data->show_in_website}}”
设置为一个特定的东西,而不是将
show_in_website
设置为什么你的意思是你想让它保持在提交表单时的状态,如果验证失败了呢?当我打开编辑页面时,它应该有来自数据库的值,当我更改值时,如果验证失败,我需要{old('input')}}值persist@RoshJ只需将
value=“1”
添加到您的输入中,您就会很好。非常感谢:)您的代码正在工作,我已经试过了,但效果不好,可能是我有一些错误,再次感谢您的帮助您可能错过了调用
withInput()不用担心,我们也会犯错误,但随着时间的推移,我们会学习。:)是的,我也认为没有验证器故障检查,它工作正常非常感谢:)你的代码工作正常,我已经尝试过了,但没有正常工作,可能是我有一些错误,再次感谢你的帮助你可能错过了调用withInput()不用担心,我们也会犯错误,但随着时间的推移,我们会学习。:)是的,我也认为没有验证器故障检查,它工作得很好