I have a form with an action attribute that calls another php page, however I'd like to validate first that one text field is not empty using javascript, how can I do this from the <input type"submit">
tag?
Asked
Active
Viewed 46 times
0

Omar Verduzco
- 115
- 9
-
Do you think add your codes to your question ? – Ivan Barayev May 06 '16 at 23:57
-
I'm not submitting this as an answer since I'm recommending a plugin, but this is a great validation tool: [jquery.validate()](https://jqueryvalidation.org/) – James Hamann May 06 '16 at 23:58
-
That level of input validation can be done without javascript (html5), no need for javascript, and certainly not a huge library like jquery. – May 07 '16 at 01:24
1 Answers
1
In html5:
<input type="text" [...] required="required" />
will allow supporting browsers to force the user to enter something before allowing the form to be submitted.
Regardless of solution: do not trust in your php code that it was validated on the client nor that it was your form to start with that sent the input to your script. So redo all validation on the server in the php code.
-
Thank you for your response, is there a way to edit what the message says when it prompts that the field is required? – Omar Verduzco May 07 '16 at 05:41
-
This might help: http://stackoverflow.com/questions/5272433/html5-form-required-attribute-set-custom-validation-message – May 07 '16 at 16:57