CodeIgniter Forums
User defined error message do not work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: User defined error message do not work (/showthread.php?tid=60772)



User defined error message do not work - El Forum - 06-24-2014

[eluser]Zombie1[/eluser]
I'm having some trouble designing my user defined error messages. My 'required' error messages work fine.

Code:
$this->form_validation->set_rules('callback_show_error_message', 'username', 'Username');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');

As you can see the two fields that use 'required' work fine whenever a user leaves a textfield blank an error is displayed.

It's just my own error message that doesn't display. Here's the function:

Code:
function show_error_message()
{
        // Display error message.
        $this->form_validation->set_message('show_error_message', 'Username or password are incorrect');
       return false;
}

If anyone has any ideas then please let me know.


User defined error message do not work - El Forum - 06-24-2014

[eluser]Tim Brownlaw[/eluser]
I have an idea... Go and read Form Validation and read the section on callbacks.

That will answer your question.



User defined error message do not work - El Forum - 06-25-2014

[eluser]Zombie1[/eluser]
Thanks but I've already read it and copied it but it still doesn't work.


User defined error message do not work - El Forum - 06-25-2014

[eluser]treenef[/eluser]
You need to display the validation errors...

<?php echo validation_errors(); ?>


User defined error message do not work - El Forum - 06-25-2014

[eluser]rm_beginner[/eluser]
Code:
$this->form_validation->set_rules('callback_show_error_message', 'username', 'Username');

try to put your callback right side.

Code:
$this->form_validation->set_rules( 'username', 'Username', 'callback_show_error_message');

hope it works.


User defined error message do not work - El Forum - 06-25-2014

[eluser]Tim Brownlaw[/eluser]
[quote author="rm_beginner" date="1403694854"]
Code:
$this->form_validation->set_rules('callback_show_error_message', 'username', 'Username');

try to put your callback right side.

Code:
$this->form_validation->set_rules( 'username', 'Username', 'callback_show_error_message');

hope it works.[/quote]

That's how it's written in the user guide!

@zombie1.... I'd seriously be reading it again and checking it against what you have written.