Reputation: 799
I had a Laravel form. It has a validation form. When it validates, if there is a validation error, so it is suppose to come back with the errors. It tells perfect the errors but the fields lose all the data the user wrote. So everything is empty. The withInput()
function is not supposed to do this job?
I will write my controller here, if you need something more tell me.
$validate = Validator::make(Input::all(), array(
'firstname' => 'required',
'lastname' => 'required',
'email1' => 'required|email',
'email2' => 'required|same:email1',
'password1' => 'required|min:6',
'password2' => 'required|same:password1',
'g-recaptcha-response' => 'required|recaptcha',
));
$captcha=Input::get('g-recaptcha-response');
//CAPTCHA CODE
if ($validate->fails())
{
return Redirect::route('getApplication')->withErrors($validate)->withInput();
}
My view here, because you request it:
@extends('templates.default.master')
@section('head')
@parent
<title>Application</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
@stop
@section('content')
<form role="form" method="post" action="{{ URL::route('postApplication') }}">
<div class="form-group col-xs-6 {{ ($errors->has('firstname')) ? ' has-error' : '' }}">
<label for="firstname">First Name</label>
<input id="firstname" name="firstname" type="text" class="form-control">
@if($errors->has('firstname'))
{{ $errors->first('firstname') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('lastname')) ? ' has-error' : '' }}">
<label for="lastname">Last Name</label>
<input id="lastname" name="lastname" type="text" class="form-control">
@if($errors->has('lastname'))
{{ $errors->first('lastname') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('email1')) ? ' has-error' : '' }}">
<label for="email1">Email</label>
<input id="email1" name="email1" type="text" class="form-control">
@if($errors->has('email1'))
{{ $errors->first('email1') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('email2')) ? ' has-error' : '' }}">
<label for="email2">Confirm Email</label>
<input id="email2" name="email2" type="text" class="form-control">
@if($errors->has('email2'))
{{ $errors->first('email2') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('password1')) ? ' has-error' : '' }}">
<label for="passsword1">Password</label>
<input id="password1" name="password1" type="password" class="form-control">
@if($errors->has('password1'))
{{ $errors->first('password1') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('password2')) ? ' has-error' : '' }}">
<label for="passsword2">Confirm Password</label>
<input id="password2" name="password2" type="password" class="form-control">
@if($errors->has('password2'))
{{ $errors->first('password2') }}
@endif
</div>
<div class="g-recaptcha col-xs-12" data-sitekey="6LeQAgATAAAAAAfJ-blWgKvb5-rUyp9xuo-iCdF9"></div>
<div class="form-group col-xs-12">
@if($errors->has('g-recaptcha-response'))
{{ $errors->first('g-recaptcha-response') }}
@endif
</div>
{{ Form::token() }}
<div class="form-group col-xs-12">
<input type="submit" value="Submit Application" class="btn btn-success">
</div>
</form>
@stop
Upvotes: 1
Views: 814
Reputation: 4644
You need to Retrieving old data in all of your input values, example.
<input type="text" name="firstname" value="{{ Input::old(firstname) }}">
Read more about Retrieving Old Data on Laravel doc.
Upvotes: 1