Re: passing variables between php forms

From: Date: Fri, 10 May 2002 04:00:03 +0000
Subject: Re: passing variables between php forms
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-96898@lists.php.net to get a copy of this message
On Friday 10 May 2002 07:41, baldey_uk wrote: > Hi sorry to annoy you AGAIN, but i cant seem to get it working.... i think > its something to do with the order that i put things in: > > > #end of html and start of php script > <?php > > > #Take the Variables from enterdetails.php that are posted from an html form > > $firstname=$_POST['txtFirstName']; > > $lastname=$_POST['txtLastName']; > > $email=$_POST['txtEmail']; > > $quantity=$_POST['txtJars']; > > $order_value=sprintf('%.2f', floatval($_POST['txtJars'])*7.0); > > echo '<INPUT type="hidden" name="testvar" > value="'.$order_value.'" />'; > > ?>php > > # end of php script back into html > > Are your details correct? > <tr> > <td valign="top" colspan="3" align="center"><form > action="confirm.php" > method="post"><input type="Submit" name="submit" > value="Yes"></form></td> > </tr> > <tr> > <td valign="top" colspan="3" align="center"><form > action="updateaddress.php" method="post"><input > type="submit" > value="No&nbsp;"></form></td> > </tr> > </font> > > If i put the echo or INPUT type outside of the php script this works, but > obviously just returns a string '.$quantity.' and not waht the variable > $quantity holds. This is extremely confusing. How do i get this php > variable to be passed to the HTML so it can be posted I thought the way i > have it the echo would make the variable testvar available to the browser, > and then i would be able to retrieve it by $_POST[testvar]; or > $_POST[$testvar]; in either the confirm.php or updateaddress.php that the > html posts to? Your form element is outside the form so is invalid and ignored by the browser. What you need is something like: <tr> <td valign="top" colspan="3" align="center"><form action="confirm.php" method="post"><input type="Submit" name="submit" value="Yes"> <INPUT type="hidden" name="testvar" value="<? echo $order_value; ?>" /> </form></td> </tr> And similarly for the second form. But I hope you're only doing this as a test. If you're implementing some kind on online shopping thing then including the value of goods ordered on a form and relying on that value when someone posts the form is a VERY BAD thing. When the form is posted you should always re-calculate the value based on item and quantity. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Every country has the government it deserves. -- Joseph De Maistre */

« previous php.general (#96898) next »