Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Two actions in one form 2 PHP processes

New Here ,
Mar 22, 2012 Mar 22, 2012

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?

TOPICS
Server side applications

Views

2.2K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2012 Mar 22, 2012

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 23, 2012 Mar 23, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines