Jump to content


Photo

Need help with Redirect after Select


  • Please log in to reply
6 replies to this topic

#1 judikrd

judikrd
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 June 2006 - 10:29 PM

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!!


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 22 June 2006 - 10:41 PM

Edit the form:
<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>

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

Legend has it that reading the manual never killed anyone.
My site

#3 judikrd

judikrd
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 June 2006 - 04:35 AM

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...

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 June 2006 - 04:39 AM

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.

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


#5 tgmd

tgmd
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 23 June 2006 - 04:40 AM

Have you tried setting it up as a SESSION or COOKIE or some other global variable that you server would remember?

#6 judikrd

judikrd
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 June 2006 - 04:47 AM

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!!

#7 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 June 2006 - 04:54 AM

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.

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users