is there any better way to higlite the form fields via Codeigniter FORM_VALICATION class? |
[eluser]Yoosuf Muhammad[/eluser]
hello, i am sort for working with CI and now i am having a practical problem (that can be done via Javascript, since i want to make accessible solution i need this requirement) is there any better way to higlite the form fields via Codeigniter FORM_VALICATION class? for example you can take similar like Ruby On Rails form validation
[eluser]CroNiX[/eluser]
Sure, in the view you can check if an error exists for a field and if it does apply a different class to that field, div, fieldset, whatever. Is that what you mean?
[eluser]Yoosuf Muhammad[/eluser]
Yes, how to set that CSS class to the Field? e.g. Code: <input type="text" id="name" name="name" /> as above, how to set the class on runtime? if there is a way please let me know. regards Yoosuf
[eluser]CroNiX[/eluser]
Code: <input type="text" id="name" name="name" <?php if(form_error('name')) echo 'class="some-highlight-class" '; ?>/> Or something like that. Then just have "some-highlight-class" defined in your stylesheet.
[eluser]Whiplash[/eluser]
I was thinking about this and decided I didn't like having to put that code into my HTML for every single field on the page. So I wrote a small function to automatically insert a css class tag if the field doesn't validate. I created a MY_form_helper.php file and threw this in there, then I call it from _parse_form_attributes which I overrode to include the call to my function. Here's the function, and I wrote up a post on it on my blog. http://64sqft.wordpress.com/2009/12/08/a...lidations/ Code: function _apply_validation_tags(&$default) It seems to work pretty well. Let me know what you think, I'm really new to PHP and Codeigniter so suggestions are welcome. Dana
[eluser]Yoosuf Muhammad[/eluser]
[quote author="Whiplash" date="1260272676"] Code: function _apply_validation_tags(&$default) It seems to work pretty well. Let me know what you think, I'm really new to PHP and Codeigniter so suggestions are welcome. Dana[/quote] how to use this helper function block?
[eluser]Whiplash[/eluser]
[quote author="Muhammad" date="1260580175"]how to use this helper function block?[/quote] I just extended the _parse_form_attributes function from the form_helper class and then added a call to my function. Dana
[eluser]Johan André[/eluser]
[quote author="Whiplash" date="1260914901"][quote author="Muhammad" date="1260580175"]how to use this helper function block?[/quote] I just extended the _parse_form_attributes function from the form_helper class and then added a call to my function. Dana[/quote] ...which basically means that you copy the MY_form_helper.php into your helpers directory and then the form_input(), form_textarea() and such will be modified to highlight your validation-errors... |
Welcome Guest, Not a member yet? Register Sign In |