0

first timer question I hope someone can help with. I want to create a menu to enable people on my site to select a size of a Hoodie and then on clicking a button go to a specific URL per size to purchase. The code I have so far is below...it feel so close to working but I just don't have the experience to know where I am going wrong. Thanks for any help you can give:

<form action="" method="post">
<select name="Size">
<option value="">Select...</option>
<option value="S">Small</option>
<option value="M">Medium</option>
</select><input type="submit" name="submit"/>
</form>

<?php if(isset($_POST['submit'])) 
{ $Paylink = $_POST['Size'];
switch ($Paylink) 
{ case "S" : header( "Location: https://buy.stripe.com/test_XYZ" );
break;
case "M" : header( "Location: https://buy.stripe.com/test_ABC" );
break;
}
}
?>
brombeer
  • 8,716
  • 5
  • 21
  • 27
  • What doesn't work? – brombeer Jan 03 '22 at 13:15
  • 1
    Is all of this in a same file and in that order? In that case, you can't set header value (Location), because your output already contains form's HTML. – Hendrik Jan 03 '22 at 13:18
  • @brombeer the menu seems to work fine but it doesn't seem to pass the variable to the switch and header redirect. I just refreshes the page and goes nowhere. – webduffer Jan 03 '22 at 13:22
  • @Hendrik Yes, all in the same file. Any advice welcome....thanks – webduffer Jan 03 '22 at 13:24
  • As @Hendrik pointed out and is written in the [header](https://www.php.net/manual/en/function.header.php) manual there shall be no output before using `header`. Read [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display?rq=1) and move your PHP block _before_ your HTML block – brombeer Jan 03 '22 at 13:24
  • How do the option values from the `select` menu relate to the endpoints specified in the urls ( or were they just dummy data urls )? – Professor Abronsius Jan 03 '22 at 15:46
  • Hi @brombeer, thanks. I have read those sections and have tried moving the blocks..but that didn't nail it I guess because that code loaded before the form action and variable was set? I tried creating a separate file to redirect to and putting a header statement in that but can't get that working.... – webduffer Jan 03 '22 at 19:21
  • @ProfessorAbronsius I have truncated the URL's for the purpose of this as I have set up test ones anyone and have multiple for varying sizes etc. My focus is getting the logic and flow working and then adding the specific URL's? Hope that makes sense. thx – webduffer Jan 03 '22 at 19:23

0 Answers0