InternetGuy Posted November 11, 2019 Share Posted November 11, 2019 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 Quote Link to comment https://forums.phpfreaks.com/topic/309512-php-script-request-perform-more-than-one-action-in-response-to-single-form-submit-button-click/ Share on other sites More sharing options...
Barand Posted November 11, 2019 Share Posted November 11, 2019 Then your "MyPHPScript.php" should retrieve the inputs from the $_GET array Send the email Update the database 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. Quote Link to comment https://forums.phpfreaks.com/topic/309512-php-script-request-perform-more-than-one-action-in-response-to-single-form-submit-button-click/#findComment-1571464 Share on other sites More sharing options...
InternetGuy Posted November 11, 2019 Author Share Posted November 11, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309512-php-script-request-perform-more-than-one-action-in-response-to-single-form-submit-button-click/#findComment-1571491 Share on other sites More sharing options...
Barand Posted November 11, 2019 Share Posted November 11, 2019 Places to look for each of the above steps,,, https://www.php.net/manual/en/reserved.variables.get.php https://www.php.net/manual/en/function.mail.php https://phpdelusions.net/pdo https://www.php.net/manual/en/function.http-build-query.php Quote Link to comment https://forums.phpfreaks.com/topic/309512-php-script-request-perform-more-than-one-action-in-response-to-single-form-submit-button-click/#findComment-1571493 Share on other sites More sharing options...
InternetGuy Posted November 11, 2019 Author Share Posted November 11, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309512-php-script-request-perform-more-than-one-action-in-response-to-single-form-submit-button-click/#findComment-1571495 Share on other sites More sharing options...
Barand Posted November 11, 2019 Share Posted November 11, 2019 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? Quote Link to comment https://forums.phpfreaks.com/topic/309512-php-script-request-perform-more-than-one-action-in-response-to-single-form-submit-button-click/#findComment-1571498 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.