Jump to content
AARRGGHHH

Action to Run JS Validation AND PHP Script

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 

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...