Welcome Guest, Not a member yet? Register   Sign In
Set Message in form validation for Certain Input Name
#1

[eluser]edidiway[/eluser]
Hi, I have problem in setting error message for codeigniter.

Generally, Codeigniter will give this error message :
Quote:The Mobile Phone field is required.
The Agreement field is required.

I want the error message become like this :
Quote:The Mobile Phone field is required.
The Agreement field must be checked

is there any simple ways to do that? because in every form validation, this things always happen, and I want to fix this in the simplest way. I can use callback function if I want, but I fill this is not the simplest way..

if I use this code
Code:
$this->form_validation->set_message('required', 'This Error Message was global for all required Rules');

All Required Rules will get the same error message and I dont want that..
#2

[eluser]oppenheimer[/eluser]
I think you are going to need to use <a href="http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks">Callbacks</a> to create your own error checking. Then you can customize the error message for this callback without impacting the regular error check.
#3

[eluser]MathBoon[/eluser]
You could override the form_validation library and create extra methods like "required_checkbox" or "required_radio".

This would not be automatic though, but i don't see any way in which CI could do this automatically.

Unfortunately CI (or php?) doesn't know what kind of input it was that led to the specific $_POST element, so you can't differ between radios, checkboxes or normal text inputs.
#4

[eluser]edidiway[/eluser]
seems there is no others way ?

Why dont CI receive the 4th parameter in set rules to set spesific error message Smile
like this maybe :
Code:
$this->form_validation->set_rules('input_agree', 'Agreement', 'required', 'Agreement Must be Checked');

okay, thanks for the answers all.
#5

[eluser]oppenheimer[/eluser]
Not a bad idea for what you want to do. You could always try to extend the form_validation.php library to add this functionality.

Extending Libraries
#6

[eluser]edidiway[/eluser]
I want that, I have tried but it is not easy anyway to extend this module.. lol.. Smile




Theme © iAndrew 2016 - Forum software by © MyBB