Laravel返回页面,使用旧输入进行验证 [英] Laravel Back to page with old input for validation
问题描述
对于更新配置文件"页面
For the Update Profile Page
我将路线用作
Route::get('editdriver/{data}', 'DriverController@EditDriver');
在我使用验证后的控制器中,
And in the controller after validation i use,
return Redirect::to('editdriver/'.$data)->withInput()->withErrors($validation->messages());
因此,该网址将为
http://localhost/project/editdriver/1
如果我清空rule
中所需的值,然后按提交表单,
If i empty the value which is required in the rule
and press submit the form,
它显示带有验证消息的旧数据.
It shows the old data with the validation message.
我需要的是,它不应显示来自数据库的旧值.
我什至尝试过
return Redirect::back()->withErrors($validation->messages());
我该怎么做??
在控制器中,我有
public function EditDriver($data=NULL)
{
$editvehicle=$data;
$DriverDetails = DriverModel::where('DriverId', $editvehicle)->get()->toArray();
return View::make('home/editdriver')->with('DriverDetails', $DriverDetails);
}
我认为
$("#Firstname").val("<?php echo $DriverDetails[0]['Firstname']?>");
并从jquery到html显示为
And displaying from jquery to html as
{{ Form::text('Firstname',null, array('id'=> 'Firstname')) }}
推荐答案
我不知道为什么要使用jQuery填写表单-这没有意义,应该删除该代码.
I have no idea why you are using jQuery to fill in your form - that makes no sense and you should remove that code.
您需要的只是这一行代码:
All you need is this one line of code:
{{ Form::text('Firstname', Input::old('Firstname', $DriverDetails[0]['Firstname']), array('id'=> 'Firstname')) }}
使用Input::old($DriverDetails[0]['Firstname'])
将使用数据库值预填充初始表单-但是如果出现验证错误,则将使用任何输入的"值填充表单
Using Input::old($DriverDetails[0]['Firstname'])
will prefill the inital form with your database value - but will then fill in the form with any 'inputted' values if there is a validation error
并确认-您的原始return语句看起来正确:
And to confirm - your original return statement looks correct:
return Redirect::to('editdriver/'.$data)->withInput()->withErrors($validation->messages());
这篇关于Laravel返回页面,使用旧输入进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!