WesleyA Posted August 26, 2015 Share Posted August 26, 2015 What is the best way to delete empty input fields, should I use php or javascript or another language? In the script the user can fill 3 or 5 input fields in the browser by html. The data will be stored in the database. But empty fields shouldnt be stored. Finally I also want to stop other crappy input, like mistakes etc. Im not sure which language is used for this matter. Is it possible to use php or is javascript better? My first focus is deleting empty input fields. Link to comment Share on other sites More sharing options...
davej Posted August 26, 2015 Share Posted August 26, 2015 You don't need to "delete" them. You just need to validate them and store only the fields that validate successfully. Preliminary validation can be done by Javascript but the final validation is always done on the server. Link to comment Share on other sites More sharing options...
Ingolme Posted August 27, 2015 Share Posted August 27, 2015 In PHP you would use empty() to determine if the field was not filled in, then you would only store data from fields that were filled in. Link to comment Share on other sites More sharing options...
WesleyA Posted August 27, 2015 Author Share Posted August 27, 2015 But do you think it is possible to check with php or maybe just with html; if a html form gets the right input ? Link to comment Share on other sites More sharing options...
davej Posted August 27, 2015 Share Posted August 27, 2015 See... http://www.w3schools.com/php/php_form_validation.asp http://www.w3schools.com/php/php_form_required.asp http://www.w3schools.com/php/php_form_url_email.asp Link to comment Share on other sites More sharing options...
dsonesuk Posted August 27, 2015 Share Posted August 27, 2015 You should validate with php this is a must!, JavaScript validation makes it more user friendly like when specific inputs can be highlight to identify a problem which does not require the need for the page to reload, unlike php validation, BUT! JavaScript can be disabled, that is why you need to perform php validation and sanitization before storing data in database to prevent SQL injection. With html5 you have new attributes, and new type attributes values such as required, number, email etc but not all of these are supported in all browsers or older browsers versions. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now