petenaylor Posted September 24, 2010 Share Posted September 24, 2010 Hi all I am in the process of creating a product page where the user can type in three initials into a form and then 'clicks add to basket'. The button doesn't use a form just a url: basket.php?action=add&id=1&qty=1 This adds the item into a basket using sessions rather than a database. The question is, how do I add three variables into my form so that they are sent via the URL and into the session? Wil I have to start again with a form? Here's the code: <td class="table-font-grey">Why not make your whip extra special by adding up to three elegantly engraved Kunstler script initials.</td> <td width="42" style="border: 1px solid grey;"><input name="initial_1" type="text" size="8" maxlength="1" height="40px" /></td> <td width="43" style="border: 1px solid grey;"><input name="initial_2" type="text" size="8" maxlength="1" height="40px" /></td> <td width="43" style="border: 1px solid grey;"><input name="initial_3" type="text" size="8" maxlength="1" height="40px" /></td> </tr> <tr> <td height="15"> </td> <td width="328" class="table-font"> </td> <td width="42" align="center" class="table-font">1</td> <td width="43" align="center" class="table-font">2</td> <td align="center" class="table-font">3</td> </tr> <tr> <td> </td> <td colspan="3" class="table-font"> </td> <td align="right" class="table-font"> </td> </tr> </table> <hr /> <p> </p> <table width="494" border="0"> <tr class="table-font"> <td width="263" height="24"> <a href="<?php echo "basket.php?action=add&id=1&qty=1" ?>" title="Add <?php echo $product['name'] ?> to Cart"> <a href="<?php echo WEB_URL."basket.php?action=add&id=1&qty=1" ?>" title="Add <?php echo $product['name'] ?> to Cart"> <img src="<?php echo WEB_URL."images/product-add-button.gif" ?>" alt="Buy <?php echo $product['name'] ?>" /></a> Many thanks Pete Quote Link to comment https://forums.phpfreaks.com/topic/214281-sending-form-variable-as-url-parameter/ Share on other sites More sharing options...
WatsonN Posted September 24, 2010 Share Posted September 24, 2010 Just change the HTML form to GET and in the PHP make sure its set to check for GET and not POST Quote Link to comment https://forums.phpfreaks.com/topic/214281-sending-form-variable-as-url-parameter/#findComment-1115064 Share on other sites More sharing options...
DavidAM Posted September 24, 2010 Share Posted September 24, 2010 It is true that you can specify GET for a FORM action which sends the form fields through the url instead of as POST data. However, I don't see a FORM in your code. It looks like you are trying to submit the form data using a link (<A href="...">). This cannot be done. (well, unless you use javascript). You have to use a submit element to send the form fields either through GET or POST. <FORM method="POST" action="<?php echo "basket.php?action=add&id=1&qty=1" ?>"> <!-- Your table here --> <INPUT type="submit" name="btnAdd" value="Add to Basket"> Note: This example sends the existing paramaters (action, id, and qty) in $_GET and sends the initials (initial_1, initial_2, and initial_3) as $_POST parameters. I just did it that way, because it is cool that you can. You should probably use GET for the form method instead of POST in this particular case, just so you don't get too confused about what's where. Quote Link to comment https://forums.phpfreaks.com/topic/214281-sending-form-variable-as-url-parameter/#findComment-1115100 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.