mahenda Posted November 23, 2019 Share Posted November 23, 2019 Is jquery/Ajax better than real/raw PHP for form validation ?! What if JavaScript is turned off on the browser?! why after someone refreshing a page on the browser, the variables used to echo error after invalid data is being submitted will return the undefined variables error?! And how to handle form validation including an empty form field, maximum amount of value entered and so on Quote Link to comment Share on other sites More sharing options...
requinix Posted November 23, 2019 Share Posted November 23, 2019 41 minutes ago, mahenda said: Is jquery/Ajax better than real/raw PHP for form validation ?! No. Validating on the user's computer means telling it what to do and hoping that it happens. You must validate on the server, and you may validate on the client too. 41 minutes ago, mahenda said: What if JavaScript is turned off on the browser?! That sounds like a good reason to not only do validation on the client. 41 minutes ago, mahenda said: why after someone refreshing a page on the browser, the variables used to echo error after invalid data is being submitted will return the undefined variables error?! Because your code and/or design is flawed. 41 minutes ago, mahenda said: And how to handle form validation including an empty form field, maximum amount of value entered and so on Handle it in whatever way you want as long as it works the way you need it to work. 1 Quote Link to comment Share on other sites More sharing options...
mahenda Posted November 23, 2019 Author Share Posted November 23, 2019 Thanks you so much Quote Link to comment Share on other sites More sharing options...
mahenda Posted November 25, 2019 Author Share Posted November 25, 2019 Check here If(empty($username){ echo ' user name is required'; } At the same time We have written a jQuery that prompt the message 'user name is required' if he/she submit an empty value. Here all warning message will be printed at the same time, and it is going to be a bad idea since we have two messages at the same time. So how to handle this?! Quote Link to comment Share on other sites More sharing options...
requinix Posted November 25, 2019 Share Posted November 25, 2019 Don't print both? Seriously, you've given me a tiny bit of code way out of context. I can't do much with that. If you want to do some basic validation with just Javascript then that's fine, but if it fails validation you don't then submit that to the server. Quote Link to comment Share on other sites More sharing options...
NotSunfighter Posted November 25, 2019 Share Posted November 25, 2019 The 'required' attribute will do the same thing. Why use JS? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted November 25, 2019 Share Posted November 25, 2019 (edited) Also, be aware that client-side code can be tampered with. JavaScript validation can be deleted / modified without disabling JavaScript. The "required" attribute can be removed. Hidden values can be modified. Extra input tags can be added. Client-side validation should be seen more as a convenience to the user. You can let them know when something is wrong before the form is submitted. However, you should not trust that validation. Sever-side validation should be implemented to prevent tampering. Edited November 25, 2019 by cyberRobot fixed typo Quote Link to comment Share on other sites More sharing options...
requinix Posted November 25, 2019 Share Posted November 25, 2019 1 hour ago, NotSunfighter said: Why use JS? Because you cannot customize the "required" validation warning that the browser gives the user. Or "pattern", which is going to tell the user something cryptic they won't possibly understand. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.