Copy link to clipboard
Copied
PHP NEWBIE HERE!
I have a form in HTML5 that needs two actions with ONE submit button. Is there a way to do that? The first action that needs to happen is to verify the CAPTCHA is correct and then the second action is submitting the form data to an email address if the CAPTCHA is correct.
Can you do this?
Copy link to clipboard
Copied
You would typically accomplish that with a single action since both CAPTCHA and email are server side processes; the form submits to a PHP page that first executes the CAPTCHA code, and then sends the email.
Copy link to clipboard
Copied
Just to add to what Bregent said:
The simple answer is no, you cannot have more than one action and method to a form, but there are many ways to control what happens after the submit button is clicked. Also, you can have more than one "submit button by giving them different names, then using a conditional like "if ($_POST['option1']) { do such and such }.
The sequence you described is typical. It is possible, upon form submission, to verify the form, email the form data, post the data to a database, then send a response to the submitter. Just remember that PHP does it all in sequence, so you can do things like change the value of variables along the way, as needed. For instance, you may want to send a date to the database in unix date format but send the same date in an email in a human-friendly format.
Also realize that you can use javascript to make on-the-fly changes and processing before the form is submitted.
Lastly, instead of using a hateful CAPTCHA, consider using a combination of data validation and a "honey pot." I do lots of forms, but I never use CAPTCHA.