displaying specific error messages in laravel 4.2 -


hello have form , have validations it. have finished doing validations in inside controller , can display error messages in view wanted error message beside input area came here code in view

{{ form::open(array('url' => 'addparentaccnt')) }}     <div class="form-group">         {{ form::label('username', 'username') }}         {{ form::text('username', input::old('username'), array('class' => 'form-control','placeholder' => 'insert username')) }}     </div>     <div class="form-group">         {{ form::label('fname', 'first name') }}         {{ form::text('fname', input::old('fname'), array('class' => 'form-control','placeholder' => 'insert first name')) }}     </div>     <div class="form-group">         {{ form::label('lname', 'last name') }}         {{ form::text('lname', input::old('lname'), array('class' => 'form-control','placeholder' => 'insert last name')) }}     </div> {{ form::submit('proceed next step', array('class' => 'btn btn-primary')) }}  {{ form::close()}} 

in bottom of view added code display error messages

@if ($errors->any()) <ul>    {{ implode('', $errors->all('<p style="color:red"              class="error">:message</p>')) }} </ul> @endif 

the code inside controller this

$rules = array ( 'username'     => 'required|min:10|max:50', 'fname'        => 'required|alpha|min:1|max:80', 'lname'        => 'required|alpha|min:1|max:80',  ); $validator = validator::make(input::all(), $rules, $messages); if ($validator->fails())  {      return redirect::to('createpa')   ->witherrors($validator)   ->withinput(input::except('password')); }  else {    //do } 

change view following:

 <div class="form-group">             {{ form::label('username', 'username') }}             {{ form::text('username', input::old('username'), array('class' => 'form-control','placeholder' => 'insert username')) }}             {{ $errors->first('username', ':message') }}         </div>         <div class="form-group">             {{ form::label('fname', 'first name') }}             {{ form::text('fname', input::old('fname'), array('class' => 'form-control','placeholder' => 'insert first name')) }}             {{ $errors->first('fname', ':message') }}         </div> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -