Jump to content
Updating IPB tonight Read more... ×

Archived

This topic is now archived and is closed to further replies.

judikrd

Need help with Redirect after Select

Recommended Posts

Hello...!

I'm rather new to php and can't find out how to redirect to a new web page after a person has chosen from a list in a select statement.

Here's what I've got:

<form name="select2" method="post">
<select name="groupChoice" id="groupChoice">
<?php for ($j=1; $j<=$i; $j++) {
echo '<option value =', $keyn[$j], '>', $selectGr[$j], '</option>'; } ?>
</select>
<?php echo $i.", ".$_POST['groupChoice'] ?>
<p><a href="combSelect.php?keyn=<?php echo $_POST['groupChoice'] ?>">Click here to buy </a>

This doesn't work -- I think it is because a person has to actually click on a Submit button before the Post variable works, right?

So, then I tried this:

<input type="submit" value="go" onclick="document.location = 'combSelect2.php?keyn=<?php echo $_POST['groupChoice'] ?>' ">

... but that doesn't work either; in fact the user isn't redirected. If I use just type="button", they get redirected, but the value is missing again.

How can I use a Submit button and still get the redirect to work?

Thanks so much for any help you can give me!!

Share this post


Link to post
Share on other sites
Edit the form:
[code]<form name="select2" method="post" action="combSelect.php">
<select name="groupChoice" id="groupChoice">
<?php for ($j=1; $j<=$i; $j++) {
echo '<option value =', $keyn[$j], '>', $selectGr[$j], '</option>'; } ?>
</select>

<p><input type="submit" name="submit" value="Click here to buy"></p>
</form>[/code]

Edit combSelect.php:
[code]<?php
$keyn = $_POST['groupChoice']; // retrieve POSTed value from form
... more code ...
[/code]

Share this post


Link to post
Share on other sites
Thanks so much for your help but... I can't use your code -- that's what I had in the first place!

The problem is, that after being in combSelect.php, from there we go to PayPal. And once in the PayPal shopping cart, one can click on "Continue shopping", which takes you back to combSelect.php -- except this time, since the page doesn't know the value of $_POST['groupChoice'] any more, you get an error message.

So I have to find a new way of doing this...

Share this post


Link to post
Share on other sites
in the top of your document (before any output) you can set a cookie, or a session to remember.

But I thought the "continue shopping" button just closed the paypal popup?

now, if after posting your data, the form doesn't reset to the right option, that's different.

[code]echo '<option value =', $keyn[$j], ($_POST['groupChoice']==$keyn[$j]?" selected":""),'>', $selectGr[$j], '</option>';[/code]

Share this post


Link to post
Share on other sites
Have you tried setting it up as a SESSION or COOKIE or some other global variable that you server would remember?

Share this post


Link to post
Share on other sites
Hmmm, great ideas, I'm sure -- but I don't know how to do session variables or cookies.

And yeah, PayPal seems to actually call the page from whence it came, unfortunately.

But, isn't there a way to put some code into the Submit button that will call the new page? Because if the URL is something like, "www.page.com?keyn=4", that works (i.e., PayPal can go back there). It's just that I haven't figured out how to get that into the redirect from the Submit button using my $_POST variable. Any ideas??

Thanks for your help!!

Share this post


Link to post
Share on other sites
typically, the paypal page is a popup. So when you say "continue shopping" it just closes itself revealing the page below it. If that's the case here (and I've done numerous paypal integrations and never seen when this was not the case) it is likely that your form is just not $_POST savvy.

try adding that code I provided earlier to your form and see what happens. Worst case scenario it won't do anything.

[code] echo '<option value =', $keyn[$j], ($_POST['groupChoice']==$keyn[$j]?" selected":""),'>', $selectGr[$j], '</option>';[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.