Laravel 4 - 2 forms with the same input names

I created two separate forms. One for entry and one for registration. They work fine on separate pages, but if they are on the same page, they print each other's error messages. I think this is because they contain the same names.

They have separate controller methods. Here is an example installation.

Registration form

{{ Form::open(['route' => 'signup']) }}

<div class="form-group">
    {{ Form::label('email', 'Email') }}
    {{ Form::text('email', null, ['class' => 'form-control']) }}
    {{ $errors->first('email', '<p class="error">:message</p>')}}
</div>

<div class="form-group">
    {{ Form::label('password','Paswword') }}
    {{ Form::password('password', ['class' => 'form-control']) }}
    <p class="help-block">Password needs to be between 6 - 8 characters</p>
    {{ $errors->first('password', '<p class="error">:message</p>')}}
</div>
<div class="form-group">

    {{ Form::submit('Sign up', ['class' => 'btn btn-primary']) }}

</div>
{{ Form::close() }}

Login form

{{ Form::open(['route' => 'login']) }}

<div class="form-group">
    {{ Form::label('email', 'Email') }}
    {{ Form::text('email', null, ['class' => 'form-control']) }}
    {{ $errors->first('email', '<p class="error">:message</p>')}}
</div>

<div class="form-group">
    {{ Form::label('password','Paswword') }}
    {{ Form::password('password', ['class' => 'form-control']) }}
    {{ $errors->first('password', '<p class="error">:message</p>')}}
</div>

<div class="form-group">

    {{ Form::submit('Login', ['class' => 'btn btn-primary']) }}

</div>

{{ Form::close() }}

routes.php

Route::get('/signup', [
    'as' => 'signup',
    'uses' => 'UsersController@getSignup'
]);
Route::post('/signup', [
    'as' => 'signup',
    'uses' => 'UsersController@postSignup'
]);

Just wondering if anyone else has run into this problem and how to solve it.

thank

+4
source share
1 answer

http://laravel.com/docs/4.2/validation#error-messages-and-views

Named Error Packages

, MessageBag . . toErrors:

return Redirect::to('register')->withErrors($validator, 'login');

MessageBag $errors:

<?php echo $errors->login->first('email'); ?>
+5

All Articles