Welcome Guest, Not a member yet? Register   Sign In
Highlighting Invalid Fields
#1

[eluser]backtoeleven[/eluser]
Hi,

Does anyone know of a way of using the form_validation library to highlight specific input fields that have failed validation?

I know there is a way to output the errors separately using the form_error() method but I am thinking more along the lines of highlighting the input field in red should it fail validation.

Anyone got any bright ideas?

Thanks,
Matt
#2

[eluser]Stefan Hueg[/eluser]
Yup I had this specific problem several days ago and here is my solution (it's a bit dirty, but it works):

Let's say you have a text input which you want to give a class named "error" if there is an error on that field.

Code:
<input type="text" class="<?= $this->form_validation->error('my_field') == '' ? '' : 'error' ?>" name="my_field" />

And that's it Smile




Theme © iAndrew 2016 - Forum software by © MyBB