Validating user input
In most web applications, there will be certain form fields that are required to process the form. We also want to be sure that all the e-mail addresses are formatted correctly, or the input must have a certain number of characters. Using Laravel's Validator
class, we can check for these rules and let the user know if something is not correct.
Getting ready
For this recipe, we just need a standard installation of Laravel.
How to do it...
To complete this recipe, follow these steps:
Create a route to hold the form:
Route::get('userform', function() { return View::make('userform'); });
Create a view named
userform.php
and add a form:<h1>User Info</h1> <?php $messages = $errors->all('<pstyle="color:red">:message</p>') ?> <?php foreach ($messages as $msg) { echo $msg; } ?> <?= Form::open() ?> <?= Form::label('email', 'Email') ?> <?= Form::text('email', Input::old('email')) ?> <br> <?= Form::label('username...