Jump to content

Action to Run JS Validation AND PHP Script


AARRGGHHH

Recommended Posts

I have a form written using HTML5 and CSS3, final validation is performed on submit with JavaScript.  Then, the form will be sent to the server, most likely using PHP's mail() function.  I don't recall how to include two items such as these in a form's action="...", I'd deeply appreciate if someone could refresh my memory! 

Thank you 

Link to comment
Share on other sites

A form only has one action in the attribute.  You can attach a submit event handler to run before the form gets submitted, but that doesn't go in the action.  The action should be the PHP script you want to process the form, and you can use Javascript to attach a validation handler.  Make sure to also validate the form with PHP, Javascript validation is only a convenience for the user, you shouldn't rely on it.

Link to comment
Share on other sites

1 hour ago, justsomeguy said:

You can attach a submit event handler to run before the form gets submitted, but that doesn't go in the action.  

Okay, so where would that go?  For example, could I put an onclick  in the submit button that will fire and validate before the action sends the mail? 

Thank you

Link to comment
Share on other sites

No! never place onclick event to form button  that is used for submission. The onsubmit event is always attached to form element, because it catches all submissions, whether from submit button/s or clicking enter/return button on keyboard while in form input element.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...