![]() |
Form Validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Form Validation (/showthread.php?tid=29707) |
Form Validation - El Forum - 04-19-2010 [eluser]invision[/eluser] Hi, I'm playing about with some very basic form validaton for a web site. However, currently when the fields are empty and I submit my form, the message outputted is: Code: The cname field is required. This happens because I use <?php echo $this->validation->error_string; ?> in my form view. Is there a way I could change this, so instead of saying each error, it would put a red border on the input element required? Would this be in the Validation class somewhere or the Form Helper? Controller: Code: class Createaccount extends Controller { Many thanks for any pointers. Form Validation - El Forum - 04-19-2010 [eluser]theshiftexchange[/eluser] FYI - yes you can do it. I dont have the code in front of me - but you would do something like if ?php echo $this->validation->error_string; = something then do html code showing the red box and do this for each field... Form Validation - El Forum - 04-19-2010 [eluser]invision[/eluser] Aaaah. That sounds about right. So this would go in my VIEW file on each element? e.g. Code: <input id="email" if <?php echo $this->validation->error_string; = 'email' { echo 'style="border:2px solid red"'; } ?> /> If you did have example code or even a link to an example it would be fantastic. Thankyou. Form Validation - El Forum - 04-19-2010 [eluser]$ilovephp[/eluser] [quote author="invision" date="1271685207"]Aaaah. That sounds about right. So this would go in my VIEW file on each element? e.g. Code: <input id="email" if <?php echo $this->validation->error_string; = 'email' { echo 'style="border:2px solid red"'; } ?> /> If you did have example code or even a link to an example it would be fantastic. Thankyou.[/quote] try this code instead (although, i am not sure): Code: <input id="email" <?php if ($this->validation->email_error != '') { echo 'style="border:2px solid red"'; } ?> /> $this->validation->fieldname_error is the way of individually identifying errors in your fields. Don't forget to add a suffix '_error'. I hope that works. Form Validation - El Forum - 04-19-2010 [eluser]invision[/eluser] Many thanks for the reply $ilovephp. Currently I'm using this for generating input fields: Code: <?php echo form_input($email); ?> Thank you. Form Validation - El Forum - 04-19-2010 [eluser]invision[/eluser] The Validation library looks good to me. Hopefully it can resolve this for me. I will post back. Form Validation - El Forum - 04-19-2010 [eluser]$ilovephp[/eluser] [quote author="invision" date="1271686244"]Many thanks for the reply $ilovephp. Currently I'm using this for generating input fields: Code: <?php echo form_input($email); ?> Thank you.[/quote] The only thing we need to edit in your input field is the style attribute. In your case, you are using the Form Helper of CI. You may want to consider the following codes: Code: $email = array( not so sure but why not give it a try... ![]() Form Validation - El Forum - 04-19-2010 [eluser]invision[/eluser] Hi again. Unfortunately it doesn't seem to like that. Straight away before form submission, I get: Code: A PHP Error was encountered Form Validation - El Forum - 04-19-2010 [eluser]$ilovephp[/eluser] [quote author="invision" date="1271687656"]Hi again. Unfortunately it doesn't seem to like that. Straight away before form submission, I get: Code: A PHP Error was encountered Ooops.. i forgot to include this code: Code: $fields['email']= 'Email Address'; Form Validation - El Forum - 04-19-2010 [eluser]invision[/eluser] Way-heeeeeey!!!! That worked perfectly. So if I wanted it to take the real value of the email field, how can I do this? And would I just do this for the other fields on my page, instead of using the array? Thank you once more for your help and patience. |