Form Validation Using Form Helper |
[eluser]mmcglynn[/eluser]
I am trying to set up validation on a simple contact form that is created using the form helper. No validation at all occurs. Do these two things even work together? In the below, the "good" keyword always shows, regardless of what is entered into the form, and the saved values set via set_value are never shown. Controller Code: // Contact View Code: echo validation_errors();
[eluser]erik.brannstrom[/eluser]
It's most likely because you are not setting the validation rules correctly. Please read http://ellislab.com/codeigniter/user-gui...ationrules, or the section below on how to set rules using an array. If you are to use an array, it needs to be multi-dimensional with one array for each field.
[eluser]mmcglynn[/eluser]
You are right about the message array. It is now correct and looks like the below. Any idea on how to preserve the entered values? Code: $config_rules = array(
[eluser]erik.brannstrom[/eluser]
Hm.. Are you getting "bad" echoed now? For the name field I think you should add it to the validation configuration array, though with an empty rules string, but as far as I can see the other fields should be populated.
[eluser]mmcglynn[/eluser]
The conditional is now correct and I am getting the validation error text. What is NOT happening, however, is the fields with valid data are not getting repopulated when the form is redisplayed with the error messages.
[eluser]erik.brannstrom[/eluser]
Quote:What is NOT happening, however, is the fields with valid data are not getting repopulated when the form is redisplayed with the error messages.So everything works then? Actually I don't have any good ideas of what the problem could be. If you look at the source, are the form fields printed correctly? If you use for example set_value('email', 'somevalue') instead, do you get somevalue as the default value when first opening the form, i.e. without having posted anything?
[eluser]Ivar89[/eluser]
I don't really see the fault but wouldn't this eb WAY easier?: Code: <label id="message">Message:</label> Code: $config_rules = array(
[eluser]mmcglynn[/eluser]
Thanks Ivar89. I guess part of my question was style related, Isn't better to generate all of the mark up from PHP? That's why I was using the Form Helper, but I am open to options. the fact is the set_value doesn't work in the form Helper code, so I may be forced to type the mark up as you suggest. That said, any idea why the set_value doesn't work in this context?
[eluser]Ivar89[/eluser]
Seems a lot more work to me so, and this works pretty good^^ I don't know why it does not work srry |
Welcome Guest, Not a member yet? Register Sign In |