Forum Moderators: coopster

Message Too Old, No Replies

Building php link from form info

         

adamnichols45

8:40 pm on Mar 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Im trying to build up a link to pass to shopping cart.

here is the form.

<form action="cart_new.php?action=add" method="post" id="cart">

<input type="text" name="qty1" size="3" value="1" maxlength="3" />

whats the best way to put them vars into a link

I have tried <a href="cart_new.php?action=add=qty1&1">

g1smd

9:35 pm on Mar 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't understand the question.

POSTing the form allows you to examine the POST variables in a script residing at the target URL.

Why are you adding parameters to a GET type URL?

londrum

9:49 pm on Mar 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if you're trying to pre-populate the form with the variables in the link, then you can do something like this

<input type="text" name="qty1" size="3" value="<?php echo $_GET['qty1']; ?>" maxlength="3" />

doing it with GET probably isn't the best choice though, because you'll have trouble changing the value to something else when they reload the page. (you'd have to change the url again, or it will just retake the old values.)
and what if the url has been amended and the variable isn't present? or if its a word instead of a number?

...and you probably just did a typo, but the link should be in this format
<a href="cart_new.php?action=add&qty1=1">

rather than
<a href="cart_new.php?action=add=qty1&1">

adamnichols45

10:17 am on Mar 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



POSTing the form allows you to examine the POST variables in a script residing at the target URL.

Couldnt see anything being carried over in address bar.

...and you probably just did a typo, but the link should be in this format
<a href="cart_new.php?action=add&qty1=1">

tried that but no success. Only way I can get it to work is through a form.

In the end I have had to just carry on using

<form></form>

for each box. so 3 forms on 1 page. Is there anything wrong doing it this way?

londrum

10:36 am on Mar 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



when you use POST it doesn't carry them over in the URL. it only does that when you use GET.

if you want to use POST, then you access them with $_POST['action']

if you use GET, then you access them with $_GET['action']

henry0

12:56 pm on Mar 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or $_REQUEST
as "one size fits all"