lynwode Posted August 9, 2013 Share Posted August 9, 2013 Howdy Folks, I have a HTML form with a drop down box that has a key pair value behind it eg: Key Value 1 Widget1 2 Widget2 3 Widget3 ..... What I want to do is pass both the key and the value to the next page so I can use the key to query the DB (the key is the pk from the DB) and the value for display purposes. Currently I have two test scripts, the first creates the drop down and passes the parameters to the second which just displays them on a page: <?php echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"; echo "<html>"; echo "<head>"; echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"; echo "<title>Test Page</title>"; echo "</head>"; //Clear Form echo "<body>"; $array = array(); echo"<form action=\"test1.php\" method=\"post\">"; echo "Year"."<select name=Year>"; echo "<option>--Year--</option>"; echo"<option value=\"1\">2008</option>"; echo"<option value=\"2\">2009</option>"; echo"<option value=\"3\">2010</option>"; echo"<option value=\"4\">2011</option>"; echo"</select>"; echo "<input type=\"hidden\" name=\"Year_Dim\" value=\"Year_Dim\">"; echo "<BR><input type=\"submit\" value=\"Submit\" /><br/>"; echo "</form>"; echo "</body>"; echo "</html>"; ?> and <?php print_r($_POST); echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"; echo "<html>"; echo "<head>"; echo "<title>Test Page</title>"; echo "</head>"; echo "<BR>"; echo "The Report was run with the following parameters. <BR><BR>"; if (isset ($_POST[Year_Dim])) { echo "Year: <B>".$_POST[Year]."</B><BR>"; }; echo "</body>"; echo "</html>"; ?> I have tried to pass both key and value but can't seem to get anywhere - its either one or the other. Does anyone have any pointers or examples that would guide me in the right direction. Any help is greatly appreciated. Cheers, Tim. Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted August 9, 2013 Solution Share Posted August 9, 2013 Pass just the key and look up the value while you're in the database anyways. Quote Link to comment Share on other sites More sharing options...
lynwode Posted August 9, 2013 Author Share Posted August 9, 2013 Good point - didn't think of that..... sometimes the blindingly obvious is our of site ! In this scenario this will work (with some SQL tweaking). If there is a scenario (can't think of one right now) where this isn't feasible is there a way of passing both key and value. Thanks for your help ! Quote Link to comment Share on other sites More sharing options...
requinix Posted August 9, 2013 Share Posted August 9, 2013 (edited) Kinda, but if you're able to get the key and value at the same time anyways then you should be able to get them again on the next page. [edit] You could pass both like "key,value" as the value, but you're still stuck validating it which requires getting the list of keys and values again anyways. Edited August 9, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
lynwode Posted August 10, 2013 Author Share Posted August 10, 2013 Yeah I thought of that too - but then you have to put logic into how they are packed. For now your original suggestion will suffice. Thanks again ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.