PDA

View Full Version : Html/php Form - Single Button Performs 2 Actions? How?


andrewf
06-17-2005, 02:31 PM
Hello,

I have an HTML form where visitors fill out their
Name: ________
Phone:________
Email: _________

And they have the option of browsing their computer for a file, and then uploading the file to my server.


The problem is I have 2 different actions and I want just 1 Button to perform both...

The first action sends the info they provided including their "name, phone, email and the name of the file they uploaded (not the actual file, just the name of it) to me via email.

That action looks like this: action="<?= $PHP_SELF ?>"



The second action is used to upload the file to my server.

It looks like this: action="uploadresults.php"


I can get the submit button to perform either one of the actions... but I can't get it to do both... And I really need just 1 button to do both.

What I would really like is for the first action (the one that sends off the email to me) to happen in the current browser window. And the second action (the one that uploads the file) to happen in a new pop up window...

So the result when you click the button would be that the page basically refreshes and shows my message saying "Thank you your message has been sent" And a second window opens that says "Your file has been uploaded."


I have been searching all over Google and it seems as though you can't really have two actions with just one submit button... But there has to be a way using JavaScript or something to perform both actions.


Any help or direction would be great!

Thanks, Andrew

ZBC
06-18-2005, 06:00 AM
Well I think I have what you need. Fisrt you would submit the first part with the email and so on. Then when you display the thank message this code will pop up the the window that will do the rest.
<SCRIPT LANGUAGE="JavaScript">

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,men ubar=0,resizable=0,width=200,height=200');");
}
</script>


<BODY onLoad="javascript:popUp('http://www..com')">
Just the width and height of the the pop up in the javascript and
put the url to the php file that submits the file with the information in the url like:
<BODY onLoad="javascript:popUp('http://www.test.com/submit.php?file=c:\file.zip')">So you can grab the infromation from the url to send to the server. Hope that helps :)

andrewf
06-20-2005, 02:51 PM
Thanks for the reply ZBC,

However I submit the first part (the email into) using "<?= $PHP_SELF ?>"
So it doesn't really load a new page... So how would I include the javascript popup function?

I currently am just using:

echo "Thanks for sending us an email"

to display the thank you message...

So at this point I am a little stuck...

Any advice?

Thanks, Andrew

ZBC
06-21-2005, 10:27 PM
When you echo the thank you message you need to put the html code around it. Like so.
<html>
<head>
<title>Some title</title>
<SCRIPT LANGUAGE="JavaScript">

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,men ubar=0,resizable=0,width=200,height=200');");
}
</script>
</head>

<BODY onLoad="javascript:popUp('http://www.test.com/submit.php?file=<? echo "$file_name"; ?>')">
<?
echo "Thanks for sending us an email";
?>
</body>
</html>The variable called $file_name is the name of the file that your php code in the pop up that will load to the server, and any other php code can go above the html code.