Question:
How do I submit an html form using Javascript but Validate it using PHP?
anonymous
2009-05-26 10:55:27 UTC
I made an HTML form and it can validate using a submit button.

How do I create a javascript submit link that will send my form to my validation page?

My Submit Link:
Submit

Full Submit Link without tags:
href="javascript:document.contact_form.submit()"

My
Tag:


Start of Validation page:
if (isset($_POST["submit"]))

If you Need anything else just tell me
Three answers:
anonymous
2009-05-26 11:33:35 UTC
Why do you want to validate your for in a different file and not in the same html file that host the form. You can add validation javascript in the same File where the form is and only after validation submit the form using javascript to submit the form.



And no you can nor submit a form using php. Php is executed on the server (also called servers side script) and then html is send to the clients browser. Javascript is executed in the browser (also called client side script).
anonymous
2009-05-26 11:04:44 UTC
You validate the form using Javascript. (It makes no sense to submit a form with missing data, or data that makes no sense, like xxx for an email address that's mandatory.) If the Javascript function finds that the form is valid it returns true, otherwise it returns false.



The PHP program checks the form inputs:



$name = isset($_POST['name']) ? trim($_POST['name']) : '';



then verifies that they're correct (not a duplicate in the database, the email domain exists, etc.) If everything checks out, it does what's needed (sends an email, enters data in a database) and, optionally, returns a message to the user that the function was carried out or that there was an error. (AJAX is the best way to do this, otherwise you have to reload the whole page just to add a "email was sent" message.)
Margaret
2016-04-04 03:33:39 UTC
The str.match function looks for a substing in a string, returns the substring if found, null if not. P.s. sorry about the horrible formatting. I can't get the hang of TAB in yahoo answers.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...