Form validation question

Joined
Feb 14, 2008
Messages
443
Reaction score
13
Points
18
Location
Chicago
Your Mac's Specs
MacBook(3,1): C2D 2.2ghz, 4g RAM, 10.7.5; iMac(12,1): 2.5ghz i5, 16gb RAM, 10.9.1; iPhone5S iOS7.04
Would it make sense to have both Javascript and PHP-based form validation on the same form? I'm thinking that the Javascript validation will be quick, but in case whoever visits the site has Javascript disabled, the PHP could be the fallback. Thoughts????
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,103
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
With Javascript you can validate and send data asynchronously without having the user specifically submit the form data..with PHP you have to submit the data for it to get validated in one shot..

Usually you use Javascript to validate the data and PHP to handle storing of said data into a database..
 
OP
dauber
Joined
Feb 14, 2008
Messages
443
Reaction score
13
Points
18
Location
Chicago
Your Mac's Specs
MacBook(3,1): C2D 2.2ghz, 4g RAM, 10.7.5; iMac(12,1): 2.5ghz i5, 16gb RAM, 10.9.1; iPhone5S iOS7.04
I know that, but again, would it make sense to do both? Yes, Javascript precludes actually sending the info to the server, but what if Javascript is disabled in the user's browser?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,103
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
If the user has disabled Javascript on their browser, they you can't do any dynamic checking, just have to wait for validation of data on submit..
 
Joined
Dec 23, 2010
Messages
110
Reaction score
4
Points
18
Location
Vilano Beach, FL
Your Mac's Specs
MBP 15" 16/500/2.3GHz, iPad 4 32GB, iPhone 5 32GB
Client vs. Server Side Validation...

What I do - and keep in mind I mainly write Enterprise type apps, so we have more controlled users - is to do field level validation on the client, including specific parsing for string formats (like email addresses, dates, etc.), then use a general DB handler on the server-side to catch any erroneous data and rollback the transaction (assuming you're using - and you should be - transactions).

So clients running JS get a nice, discreet validation notification (i.e., "Please use the format mm/dd/yyyy for the date"), plus things like edit masks, and if for some reason the JS fails, an exception "catch all" that indicates something like "Please confirm the information you entered is correct"). Maybe hang a few static examples next/under the fields to note the expected format.

Then you don't have to manage field level in two places and if something changes, like you can accept dates in dd/mm/yy, then it's just one change at the client.

Just my $0.02. :)

[edit]

Alternately, there's always "No Javascript, No Service" :D
 
OP
dauber
Joined
Feb 14, 2008
Messages
443
Reaction score
13
Points
18
Location
Chicago
Your Mac's Specs
MacBook(3,1): C2D 2.2ghz, 4g RAM, 10.7.5; iMac(12,1): 2.5ghz i5, 16gb RAM, 10.9.1; iPhone5S iOS7.04
heh...yeah, but "No, Javascript, No Service" could also mean "No Purchase." :)
 
Joined
Mar 4, 2011
Messages
69
Reaction score
0
Points
6
Your Mac's Specs
13' Macbook Pro mid 2010, OS X 10.6.7, Core 2 Duo, 4gb RAM, 250gb HDD
All my forms I use a Jquery form validation that works pretty well, in my case, We have control if js is enable/disable, browser and so on.

Don`t know if it works, but you could do like, check if js is enable, if so, run a js validation, if not, drop the js validation and run just in submit with PHP
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top