mercredi 14 octobre 2015

Adding buttons in validation lines

Hello guys,

I just started working with laravel and I was wondering if there is a way to put links/buttons in your validation lines.

For example I created a basic registration page (followed the laravel docs). When somebody is trying to register an account with a wrong email (only specific email account will be registered directly, the others will be put on a waiting list), the user will get a little error message saying that they will be put on a waiting list and a button if they would like to be on this waiting list.

so here is my code:

Auth/AuthController

protected function validator(array $data)
{
    return Validator::make($data, [
        'firstname' => 'required|max:255',
        'lastname' => 'required|max:255',
        'username' => 'required|max:50|unique:users',
        'email' => 'required|email|max:255|unique:users|http://regex:/@student\.test\.be$/',
        'password' => 'required|confirmed|min:6',
    ]);
}

Validation.php //Custom Validation Language Lines

'email' => [
        'unique' => 'This email is already already registered',
        'required' => 'Email is required.',
        'regex' => 'some text <button>want to be on the waitinglist?</button>',
    ],

And then there is a basic register view with a form and the error messages

@if (count($errors) > 0)
    <div class="alert alert-danger">
        @foreach ($errors->all() as $error)
            {{ $error }}
        @endforeach
    </div>
@endif

Thanks a lot!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire