Jump to content
InternetGuy

PHP Script Request: Perform More Than One Action in Response to Single Form Submit Button Click

Recommended Posts

You would think the answer would be all over the Internet and easy to find, but it’s not. I have searched many times, and in all the multitude of search results I have still never found an adequate usable answer. The MOST you ever find is someone saying how easy it is with PHP, but they don’t tell you how, even when the person they are answering asks them (odd). You can be that one in a billion person who finally answers it for real and helps someone out.

I have a simple HTML form with data fields first_name, last_name, email, phone, country, a few hidden inputs, and a single submit button, like so:

(Please note: the method is GET, not Post.)

<form action="https://MyDomainOnMyServer.com/MyPHPScript.php”> 
<input type="text" name="first_name" value="" />
<input type="text" name="last_name" value="" /> 
<input type="text" name="email" value="" /> 
<input type="text" name="phone" value="" /> 
<input type="hidden" name="type" value="type123"> 
<input type="hidden" name="project" value="new123"> 
<select required name="country"> 
<option value="">Choose your country</option> 
<option value="US">United States</option> 
<option value="CA">Canada</option> 
<option value="GB">United Kingdom</option> 
<option value="Many More">Many More Countries</option> 
</select> 
<input type="submit" value="Submit Form" /> </form>

NOTE: Originally, the form action would have been:

action="https://TheirExampleDomainOnTheirRemoteServer.com/TheirRemotePHPScript.php" name="form1234"

Upon clicking the single submit button only, what I need to have happen is this:

1. Send me an email to whatever@whatever.tld containing all the form submission data

2. Place the form submission data into a MySQL database having the corresponding data fields

3. Send the form submission contents including the hidden input values to "https://TheirExampleDomainOnTheirRemoteServer.com/TheirRemotePHPScript.php" name="form1234" AS IF that had remained set as the original form action to begin with

So basically what I’m trying to obtain is the cleanest possible PHP script that will do those three things, which is essentially what others have asked for over the years in search results I have found, but no one has ever provided it in a clear instance that works. If I can just see such a script, I should be able to see how it works and then do what I need. Thanks.

Reply

Share this post


Link to post
Share on other sites

Then your "MyPHPScript.php" should

  1. retrieve the inputs from the $_GET array
  2. Send the email
  3. Update the database
  4. Use http_build_query() to rebuild the querystring then use header("Location: NEW URL WITH QUERYSTRING) to send to remote page.
19 minutes ago, InternetGuy said:

If I can just see such a script

 = euphemism for "if someone will write it for me (for free)", which is probably why you can't get the answer you really want.

Share this post


Link to post
Share on other sites
16 hours ago, Barand said:

= euphemism for "if someone will write it for me (for free)", which is probably why you can't get the answer you really want.

Thanks for the outline, that does help a bit.  I don't actually do PHP and have only dabbled in it a few times.  I know it's good stuff.  However, I did do something else in IT for about 15 years.  I have lots of experience finding solutions online and have a very good sense of what one should expect to be able to find online.  That said, I think it's both odd and even pretty ridiculous that there are not simply many examples of ready made scripts for these simple needs to be easily found in many places online, so it's not quite the way you characterize it.

Share this post


Link to post
Share on other sites
23 minutes ago, Barand said:

Places to look for each of the above steps,,,

Thanks.

You know, I'd also like to share a sentiment about the big picture.  Not being able to find good simple PHP script examples for this is one thing, but what's far worse is that after all these years and still in the year 2019 it is APPALLING that there hasn't been an improvement, change, upgrade, whatever you want to call it, by whoever does such things for HTML, so that one still can't simply just add multiple actions to HTML forms to run after a single submit and not even need lots of new convoluted other script code.  I think I found evidence of people asking how to do multiple actions from one submit at least as old as the year 2000, and there's probably more online from before that.

Share this post


Link to post
Share on other sites

OK, so if instead of 1 action you have three separate scripts specified as actions for the form - but you still have to write the code to do those actions. Each of those three would have to do step 1 (get the data) thus tripling that code.

If one step fails, do you still want too do the others? How do you control that if they are now separated?

What would you gain?

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.   Restore formatting

  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.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.