GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Best way to validate forms? (https://gfy.com/showthread.php?t=957267)

Jakez 03-07-2010 08:28 PM

Best way to validate forms?
 
Does anyone have any tricks/tips on validating forms (no plugins)?

There doesn't really seem to be any universal way to make a javascript function that will suit everything, you almost have to hard code form/input names into the function, which is nasty if you're going to be working with a lot of forms in a project.

I mean I could make something that checks for empty fields or validates an email address but what if I need to see if a <select> listbox value=="this" and if it does then make sure this <input> field=="this".. things would get really messy..

Jakez 03-07-2010 08:39 PM

Plus you have to worry about people doing malicious things and getting past your javascript validation so you have to also pass everything through PHP or something.

candyflip 03-07-2010 08:43 PM

Tried jquery?

http://www.webreference.com/programm...rm_validation/

fris 03-07-2010 08:46 PM

jquery has some nice ones

fatfoo 03-07-2010 08:50 PM

jquery - I guess that's it.

Jakez 03-07-2010 09:19 PM

Of course... I'm becoming very familiar with jquery now lol. Still kind of have the same problem though, I guess there will just have to be another function for every form? Gross..

fris 03-08-2010 05:58 AM

Quote:

Originally Posted by Jakez (Post 16928201)
Of course... I'm becoming very familiar with jquery now lol. Still kind of have the same problem though, I guess there will just have to be another function for every form? Gross..

not at all

Jakez 03-08-2010 06:19 PM

Ok I have like 20 jquery.com pages open trying to figure out how to do this but none of them work, lets say I have a few of these:
Quote:

<select id=stuff[0] name=stuff[0]>
<option value="thing">Thing</option>
<option value="other_thing">Other Thing</option>
</select>

<select id=stuff[1] name=stuff[1]>
<option value="thing">Thing</option>
<option value="other_thing">Other Thing</option>
</select>
Ok, I need to go through the stuff[] array and find out if ANY of them have "thing" selected. Major confusion.

I think the closest I've came is:
Quote:

var wtf=$('#stuff[0]').val();
No luck. Tried the inArray()'s and indexOf()'s and they don't seem to return anything either.

Jakez 03-08-2010 06:42 PM

I can get the value of a <select> just fine, but since I have many of them stored into an array it's made this a lot more difficult.

Jakez 03-08-2010 09:22 PM

LOL I think I finally stumped everyone. I did find a solution though:

Quote:

var selects = $("select[name^=stuff]");
var wtf = $.inArray("thing",selects.map(function() { return $(this).val(); }).get()) > -1;
Returns true or false.


All times are GMT -7. The time now is 06:24 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123