Welcome Guest, Not a member yet? Register   Sign In
Password Hint is Submitting with Form Submit
#1

[eluser]Barwick[/eluser]
Is there any way to set specific words in the "form_validation->set_rules" function? Right now I'm using jQuery to put password hints into my form fields. By doing so, if I hit form submit, those values are entered - when they shouldn't be. I know I can prevent this via jQuery. But I'd like to keep the validation run through the controller...

For example, I have this:
Code:
$this -> form_validation -> set_rules('user_name', 'Username', 'trim|required|min_length[4]|xss_clean|callback__user_check');

Can I prevent the field from validating is the word Username is in the form field? Must be a way...can't find anything in their documentation or online.
#2

[eluser]Barwick[/eluser]
Oops...CI won't allow me to edit post...SHOULD BE <b>TEXT HINTS</b> not PASSWORD HINTS. Duh!
#3

[eluser]CroNiX[/eluser]
Why not just use the HTML5 placeholder attribute?

Code:
&lt;input type="text" name="user_name" placeholder="Enter your name" /&gt;

another thing you can do is use js to check the submitted form before it actually submits and remove the text from the fields that match your custom placeholder text so that it doesn't get sent in the first place (since it shouldn't be)
#4

[eluser]Barwick[/eluser]
[quote author="CroNiX" date="1351711940"]Why not just use the HTML5 placeholder attribute?

Code:
&lt;input type="text" name="user_name" placeholder="Enter your name" /&gt;

another thing you can do is use js to check the submitted form before it actually submits and remove the text from the fields that match your custom placeholder text so that it doesn't get sent in the first place (since it shouldn't be)[/quote]

I thought of both of those naturally first... being a web designer. However, I'll run into problems with older browsers re: HTML5. It's a registration form, so I can't risk those fields showing up blank in IE or something.

jQuery I'd like to avoid for this. don't want to separate the validation.

CI text_helper has a function that might work. Could I do a callback with word_censor() you think? or is that complicating things?
#5

[eluser]CroNiX[/eluser]
Why the objection to using jQuery to remove them since that's also how you said you're setting them? This isn't separating the validation. It's only sending data that SHOULD be validated and not sending your "hints" and it would all be done in the same place, which would be more efficient than having to track them in the JS and ALSO in the (PHP) validation. It would only be undoing what you had it do originally if the value is the same as the hint.

Or you could also just use a jQuery placeholder script to add the functionality for older browsers, which seems easiest:
https://github.com/andrewrjones/jquery-p...der-plugin
#6

[eluser]Barwick[/eluser]
Valid points man, valid points. Like that placeholder script. Checking it out now. Def easiest route to take.
#7

[eluser]Barwick[/eluser]
Works like a BOSS. It completely replaced the jQuery script I made for the text hints altogether. Thanks for your help!
#8

[eluser]Aken[/eluser]
Here's another good JS + CSS combo for improving forms. It also includes a placeholder script for non-supporting browsers. http://formalize.me/




Theme © iAndrew 2016 - Forum software by © MyBB