Transfer form input data to multiple places, one being a popup on submit
this is my first Stackoverflow question and I'm teaching myself PHP, so I apologize if this question is rather basic. I've searched on this sit开发者_如何转开发e and others and seen partial answers, but most were too specific (and had other complexities) for me to know what code did what.
I'm trying to create a form on one page of my site, that when submitted will send the data to an email address, and also bring up a popup window. In addition, there is a conditional textbox that if filled in, will send the data to a second email address. The popup window will display the user's inputted data from the previous page, though highly stylized with CSS.
<form action="php_page.php" method="POST">
<input type="text" id="name" value="Name" /><br />
<textarea id="goal1" value="Short-Term Goal"></textarea><br />
<textarea id="goal2" value="Mid-Term Goal"></textarea><br />
<textarea id="goal3" value="Long-Term Goal"></textarea><br />
<input type="text" id="email" value="Email Address" /><br />
<input type="submit" OnClick="PopUp()" id="submit" />
</form>
On the php_page.php, from what I've read I need some type of basic junction to allow the form to send its data multiple locations. Unfortunately, I don't really understand what that would look like, nor how to set up the conditional that would send any form with a filled out email address to an additional location.
The PopUp script currently looks like this:
function PopUp() {
window.open( "php_page.php", "myWindow", "status = 0, height = 500, width = 500, resizable = 0" )
}
So, I guess the questions are (1) Is this the right way to go about it? (2) What does php_page.php end up looking like in terms of directing the POST data? (3) Do I need to create a third page for PopUp() to redirect to, instead of going back to php_page.php? (4) Would this still work with HTTPS?
Thank you all in advance. Even if nobody answers this, the community here has made learning anything about PHP so much simpler than it otherwise would be.
What you'd want to do is force the post to go through the popup window. Easiest method is to put a target="myWindow"
on the <form>
tag, though this isn't valid HTML anymore, but is supported by all the major browsers. That'd pop up a new window and send the post through that window. Then your server-side script would kick in, process the post, and can return the form data in the "highly stylized" format.
You can't "tell" the PHP script to send the data to another browser window. The webserver has no concept of windows, there are only HTTP requests and responses. Those requests are also done on a per-window basis, so you can't say "send data from window X but send the reply to window Y".
An alternative would be to send the POST via an AJAX request. The javascript code could then pop up the new window and fill in its contents dynamically, but this is all dependent on the client having Javascript enabled, so isn't 100% reliable.
精彩评论