Forum Moderators: open

Message Too Old, No Replies

Redirecting PHP form, based on selection in the form.

So aggravated :(

         

tsk928

2:58 am on Oct 25, 2006 (gmt 0)

10+ Year Member



I'm trying to submit the form, and redirect the user to either www.site1.com or www.site2.com, based on which they select in the form.

For example:

<select name="redirect"><option value="">Select One</option>
<option value="http://www.site1.com">Choice 1</option>
<option value="http://www.site2.com">Choice 2</option>
</select>

Then they submit the form, and they go to site1 or site2, based on what they pick.

I'm REALLY hoping someone can help, as I'm exasperated trying to figure this out. I've searched and searched and can't find diddly squat. :)

Thanks,

Karen

physics

6:16 am on Oct 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi tsk928, welcome to WebmasterWorld.com!

You actually don't need javascript to do this. You need a block of PHP code that will take the form input and display a redirect (you can use meta redirect or http redirect codes). So something like:

<html>
<head>
<title>...</title>
<?php
if($_REQUEST['redirect']){
print "<meta http-equiv='refresh' content='0; url={$_REQUEST[redirect]}'>";
}
?>
</head>
<body>
...
<form target='' method='POST'>
<select name="redirect"><option value="">Select One</option>
<option value="http://www.site1.com">Choice 1</option>
<option value="http://www.site2.com">Choice 2</option>
</select>
...
</form>
</body>
</html>

tsk928

11:24 am on Oct 25, 2006 (gmt 0)

10+ Year Member



Ohhh so happy to see a response, thank you!

So, I add this snippet in the <head> section and that's it? Or should I add that somewhere in the existing PHP script?

<?php
if($_REQUEST['redirect']){
print "<meta http-equiv='refresh' content='0; url={$_REQUEST[redirect]}'>";
}
?>

Karen

**added

So, I tried copy/pasting the above code in the head section, and it didn't work. Perhaps I need to take off the javascript already in place?

tsk928

11:59 am on Oct 25, 2006 (gmt 0)

10+ Year Member



Ok, sooooo I cut the original redirect stuff from the actual php file, and added what you gave me and it worked! Thank you so much!

I do, however, have another question. LOL

Is there a way to make the redirect page, pop up in a new window, and have the actual form redirect somewhere else?

Karen :)

jatar_k

5:28 pm on Oct 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the only way I can figure to do that is to have a javascript function onSubmit for the form and have that popup a new window with the url

then have it submit the form as usual afterwards

I am guessing that would work, though javascript isn't my strong suit :)

physics

11:39 pm on Oct 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




Is there a way to make the redirect page, pop up in a new window, and have the actual form redirect somewhere else?

What is your reasoning as to why you want to do this? This seems like a bad idea from a useability perspective.

tsk928

11:49 pm on Oct 25, 2006 (gmt 0)

10+ Year Member



Well, because I can't think of another option. See, my form is an order form, and my new payment processor does not provide a link back to my site. So, I thought maybe I could configure it to when the user hits submit, the new window opens with the payment info, so they can pay, and then when they're done, the form window can go to the appropriate redirect page. Know what I mean? Ugh, it all sounds SO difficult.... :(

Karen

physics

4:10 am on Oct 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might be able to use an iframe. Send the users to a page with an iframe embedded in it with your form. When they hit submit the form submits to your payment processor's site and thus the transaction can be completed. In this case there may not be a return to shopping button but at least the customer has not left your site and you can have enticing links at the top for them to use to continue shopping.

More on iframes:
[cs.tut.fi...]

tsk928

10:07 pm on Oct 27, 2006 (gmt 0)

10+ Year Member



Thank you, I'll try that. :)