former icon indicating copy to clipboard operation
former copied to clipboard

Custom message seems not to work

Open trankhanh opened this issue 13 years ago • 3 comments

Using custom $message variable to replace the default error message by including this code in controller, but it won't work for now:

$messages = array( 'dob' => 'Date of birth instead of dob field' );

$validation = Validator::make($input, User::$rules, $messages);

trankhanh avatar Aug 22 '13 09:08 trankhanh

Hm that's weird, Former directly fetches the MessageBag from session, if your message is set correctly it should use it. Can you past your form's code ?

Anahkiasen avatar Aug 22 '13 11:08 Anahkiasen

Hi anahkiasen, here is the code I used before. Currently I'm still mixing Former and Form. in controller:

    public function store()
{
    $input = Input::all();

    // change 'dob' error massage
    $messages = array(
        'dob.required' => 'Test',
        // 'before' => 'Second test'
    );

    $validation = Validator::make($input, User::$rules, $messages);

    if ($validation->passes())
    {
        $this->user->create($input);

        return Redirect::route('users.index');
    }

    return Redirect::route('users.create')
        ->withInput()
        ->withErrors($validation);
}

in View:

{{ Former::date('dob')->label('Date of birth:')->placeholder('Date of birth') }}

trankhanh avatar Aug 22 '13 15:08 trankhanh

I've tried code based closely on the above for both Twitter Bootstrap 2 and 3, and it works fine for me in both cases.

Are you using the master or the develop branch? Which framework are you using? Could you paste your rules and your full form?

petercoles avatar Oct 19 '13 22:10 petercoles