11.08.2017 Views

codebright

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Validation 198<br />

33<br />

34 {{-- Password confirmation field. -----------}}<br />

35 {{ Form::label('password_confirmation', 'Password confirmation') }}<br />

36 {{ Form::password('password_confirmation') }}<br />

37<br />

38 {{-- Form submit button. --------------------}}<br />

39 {{ Form::submit('Register') }}<br />

40<br />

41 {{ Form::close() }}<br />

We can use the get() method on the validation errors object to retrieve an array of errors for a<br />

single field. Simply pass the name of the field as the first parameter to the get() method.<br />

Let’s resubmit the form. This time, place a single exclamation ! mark within the username field.<br />

Let’s take a look at the errors that appear above the username field.<br />

• The username may only contain letters and numbers.<br />

• The username must be at least 3 characters.<br />

That’s better. Well… it’s a little bit better. Most forms only show a single validation error per field,<br />

so as not to overwhelm the application’s user.<br />

Let’s take a look at how this is done with the Laravel validation errors object.<br />

1 <br />

2<br />

3 Registration form for Phill's Parks<br />

4<br />

5 {{ Form::open(array('url' => 'registration')) }}<br />

6<br />

7 {{-- Username field. ------------------------}}<br />

8 {{ $errors->first('username') }}<br />

9 {{ Form::label('username', 'Username') }}<br />

10 {{ Form::text('username') }}<br />

11<br />

12 {{-- Email address field. -------------------}}<br />

13 {{ $errors->first('email') }}<br />

14 {{ Form::label('email', 'Email address') }}<br />

15 {{ Form::email('email') }}<br />

16<br />

17 {{-- Password field. ------------------------}}<br />

18 {{ $errors->first('password') }}<br />

19 {{ Form::label('password', 'Password') }}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!