php forms

Associate
Joined
19 Jul 2006
Posts
1,847
Is there a clever way of doing this.

Say if i have a web page that is offering coffee for example and there is 3 sizes small medum and large. and each of these have a button that takes you to an online order form.
I want the form to either have an auto populated feild or a hidden feild so that when submitted I can see which size they have chosen with out them having to fill it in on the form.

Is this possible and can i use the same form and get the buttone on the previouse page to fill in the feild or will I have to have 3 seperate forms?

I know the easiest way would be to put a drop down list on the form but just want to see if i can make it a bit better.

TIA
 
It is possible. Probably just a session variable to pass the information to the next form/page would be fine.
 
If you're using a button in a form to select the size, you could identify the size when generating the form by checking for the button name in the POSTed data.
If you're using links to the different sizes, send a variable in the URL with the size and use that while generating the form.
 
I'm only just learning PHP, but I managed to do this.
You can use PHP to echo a form element with type="hidden" and value=$_POST['size'].
It should take the size from the last page's form and insert it into the new one.

I'll have a look and see how I did it when I get a chance.
 
Page 1

user submits form saying "large coffee". Form action="page 2" (order form).

<input type="text" name="coffee_size" value="">
or
<input type="radio" name="coffee_size" value="small"> Small
<input type="radio" name="coffee_size" value="medium"> Medium
<input type="radio" name="coffee_size" value="large"> Large
or
<input type="submit" name="coffee_size" value="small">
<input type="submit" name="coffee_size" value="medium">
<input type="submit" name="coffee_size" value="large">

Page 2

<input type="text" name="coffee_size" value="<?php echo $_REQUEST['coffee_size']; ?>" readonly="readonly">

<other order stuff>

you can cahnge REQUEST to whatever method you choose, post of get.
 
Last edited:
Back
Top Bottom