PDA

View Full Version : Posting to two different scripts at once


Jasont
07-07-2004, 12:44 AM
Can someone please tell me the exact code I should use to combine these two forms into one, so that the form posts to both scripts?

It is basically two sign-up forms for my hockey newsletter. The problem is, I need for both scripts to be posted to, without my subscribers having to fill in their name and email twice.

Thank you for any help, it is MUCH appreciated.


Form #1:
---------------------------------------------------------------------


<form method="POST" action="http://www.hockeydiscounts.com/cgi-bin/sf/subscribe2.cgi">
<center><table border="0" cellspacing="0" cellpadding="1"><tr><td>
<FONT SIZE="2">Email address:</FONT></td><td> <input type="text" name="emailaddy" size="20"></td></tr><tr><td>
<FONT SIZE="2">First Name:</FONT></td><td> <input type="text" name="fname" size="20"></td></tr><tr><td>
<FONT SIZE="2">Last Name:</FONT></td><td> <input type="text" name="lname" size="20"></td></tr><tr><td>
</td></tr></table>
<input type="submit" value="Click Here"></center>
<input type="hidden" name="action" value="go">
</form>
---------------------------------------------------------------------

Form #2

---------------------------------------------------------------------


<form method="POST" action="http://www.hockeydiscounts.com/cgi-bin/email/mlm.cgi">
<p>Email address: <input type="text" name="email" size="20"><br>
First Name: <input type="text" name="fname" size="20"><br>
Last Name: <input type="text" name="lname" size="20"><br>
Edit this text for 4th field: <input type="text" name="fourth" size="20"></p>
<p><input type="submit" value="Add Address"></p>
<input type="hidden" name="action" value="signup"><input type="hidden" name="list" value="hockeycontests">
</form>

---------------------------------------------------------------------

dswimboy
07-07-2004, 03:29 AM
yes, the only way i know how is to combine the two scripts, and make one form for your users to use. (i'm assuming the forms are on the same page?)

i know this kinda sucks, but there is, to my knowledge, no way to post to two scripts at once.

mlseim
07-07-2004, 03:48 AM
You combine all of the necessary fields into one form. When the form is filled out, it then send the variables to the first script.

Inside the first script, it grabs all of the variables and does it's normal
thing with the variables it needs. The other variables are parsed, but
not used with the first script.

Then, when it's done emailing or whatever, you put in a line like this:

print "Location: http://www.hockeydiscounts.com/cgi-bin/sf/subscribe2.cgi?emailaddy=$emailaddy&fname=$fname&lname=$lname\n\n";

That executes the other script, passing the necessary variables to
the other script.

This way, you only have to combine the two forms and alter only the
first script. The second script remains untouched.

Maybe my explanation is confusing? I hope you see what I mean.

Jasont
07-07-2004, 04:21 AM
I understand what you mean, in terms of how the variables will be passed along.

Are you saying I take this code:

print "Location: http://www.hockeydiscounts.com/cgi-bin/sf/subscribe2.cgi?emailaddy=$emailaddy&fname=$fname&lname=$lname\n\n";

and put it inside the other cgi file:

http://www.hockeydiscounts.com/cgi-bin/email/mlm.cgi

In other words the mlm.cgi file.

If so, where should I place the code? On the last line of the script?

mlseim
07-07-2004, 12:58 PM
Yes, that's what I mean ...

The line would go inside whichever script you are using
in the FORM ... when you combine both forms into one,
you will only be calling one script.

The FORM runs one script, and the Print "Location line
runs the other script.

You can put the line at the end, after it does it's thing ...
which is probably emailing someone.

The script probably now displays a "thankyou" message,
or jumps to a confirmation page? That's where it would go.

-----------------------------------------------------------------

Jasont
07-08-2004, 04:34 AM
Thx mlseim

mcgmark
07-31-2006, 04:24 PM
Sorry to bring up a dead thread but it looks like this would solve my problem.

I need to run 2 CGI scripts with 1 form.

So i need the form to submit all of the fields and then e-mail them to me.

and then the second part is running a second script that takes a user selected file and upload it to the server.

So i want to use this to run the second script to upload the file.

print "Location: http://www.mydomain.com/cgi-bin/upload.cgi?FILE1=$FILE1";

It doesn't seem to send the data from FILE1 thru because my upload script is giving me an error about file type...

How can I get this to actually work?

mlseim
07-31-2006, 05:10 PM
mcgmark....

You're right, I don't think you can pass the file that way.

Try doing the file upload thing first, then pass the form variables
to the next script and do the email second ... since they would be
simple variables, not a filehandle.

Or, create a single script that does both. It uploads the file and
then sends the email, all in one script.

EDIT ...

Also, you didn't mention anything about security. If the user has the
right to upload anything they want, and whether sessions are involved,
etc. This could escalate into a big deal when you're dealing with file
uploads and emails. You have spammers to worry about and people who
want to crash your server.

mcgmark
07-31-2006, 05:24 PM
Wow thanks for the quick response.

I will swap the order and give that a shot.

mcgmark
07-31-2006, 06:54 PM
Not working depending where in my script i put this code i either get no response or i get a Internal Server Error #500

could this be too many variables to pass thru?

print "Location: http://www.mydomain.com/cgi-bin/apply.cgi?FIRSTNAME=$FIRSTNAME&LASTNAME=$LASTNAME&ADDRESS=$ADDRESS&APT=$APT&CITY=$CITY&PROVINCE=$PROVINCE&COUNTRY=$COUNTRY&POSTAL=$POSTAL&PHONE=$PHONE&FAX=$FAX&EMAIL=$EMAIL&RECENTJOB=$RECENTJOB&WEBSITE=$WEBSITE&SALARY=$SALARY&TOPSKILLS=$TOPSKILLS&HIGHESTEDUCATION=$HIGHESTEDUCATION&CAREERFOCUS=$CAREERFOCUS&RadioGroup1=$RadioGroup1&RadioGroup2=$RadioGroup2&AUTHORIZE=$AUTHORIZE&LANGUAGE=$LANGUAGE&PROFICIENCY=$PROFICIENCY";

Thanks

Edit:

enctype="multipart/form-data"

that in <form> is causing me problems.. I need that line to upload the file.. but that line won't allow the none file fields to submit...

what can I do for a form that has both user entered data and a file field?