Page 1 of 1

Help needed to POST values

Posted: Tue Feb 12, 2013 11:34 am
by bbo
I have some problems with this code.

I'm trying to POST some values from the Select box and the Options to another page called "cart.php"

Here is the code:


Code: Select all

<form id="form1" name="form1" method="post" action="cart.php"  target="_self">
    
     <select name="sizetable" id="sizetable">
            <option  value="<?php echo $size_1?>"><?php echo $size_1?></option>
			<option  value="<?php echo $size_2?>"><?php echo $size_2?></option>
			<option  value="<?php echo $size_3?>"><?php echo $size_3?></option>
			<option  value="<?php echo $size_4?>"><?php echo $size_4?></option>
     </select>
   
   <input type="option" name="colsel" id="color_white" value="Hvid"/>
   <input type="option" name="colsel" id="color_black" value="Sort"/>
   <input type="option" name="colsel" id="color_grey" value="Grå" />
   <input type="option" name="colsel" id="color_lightred" value="Lys Rød";/>
   <input type="option" name="colsel" id="color_red" value="Rød" />
   <input type="option" name="colsel" id="color_pink" value="Pink" />
   <input type="option" name="colsel" id="color_blue"value="Blå" />
   <input type="option" name="colsel" id="color_lightblue" value="Lys Blå" />
   <input type="option" name="colsel" id="color_green" value="Grøn" />
   <input type="option" name="colsel" id="color_lime" value="Lime" />
   <input type="option" name="colsel" id="color_yellow" value="Gul" />
   <input type="option" name="colsel" id="color_orange" value="Orange" />
   <input type="option" name="colsel" id="color_purple" value="Lilla" />
   <input type="option" name="colsel" id="color_silver" value="Sølv" />
   <input type="option" name="colsel" id="color_gold" value="Guld" />
   <!--</form>-->
    

<!--   <div style=" z-index:100;position: absolute; left: 620px; top: 0px; width: 154px; height: 38px;" align="right"> -->
   
   <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />  
   <input type="hidden" name="sizetable" id="sizetable" value="<?php echo $size_1; ?>" /> 
   <input type="hidden" name="colsel" id="colsel" />
   <input type="image" name="imageField" id="imageField"  src="siteimages/legikurv.png"  title="Læg varen i indkøbskurver" /> 
   </form>
-------------------------------

In the cart.php I have this code:

Code: Select all

if (isset($_POST['pid'])) {
           $pid = $_POST['pid'];
           $pd = $_POST["sizetable"];
           $pd1 = $_POST["colsel"];
}
--------------------------------

I'm able to get the value from $_POST['pid'], but the other two values gives me nothing.
Can any one of you tell me what i'm doing wrong!

Regards Benny

Re: Help needed to POST values

Posted: Tue Feb 12, 2013 12:32 pm
by jraede
First of all I don't think input type="option" is a valid type. Do you mean to use radio?

Second, you have hidden inputs at the bottom with the same name as those that are visible. The values in the hidden inputs will overwrite the values chosen in the "sizetable" and "colsel" fields. Why do you have those hidden fields?

Re: Help needed to POST values

Posted: Tue Feb 12, 2013 12:41 pm
by bbo
I actually just copied this piece of code: <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> and filled in some other names and id.

I actually thought that was the way to make this work.. I'm very new to php coding, but I'm still learning. :wink:

And you are right. I should have used radio instead of option.....

Re: Help needed to POST values

Posted: Tue Feb 12, 2013 2:18 pm
by bbo
I've made the changes you mentioned but it still not working

Re: Help needed to POST values

Posted: Wed Feb 13, 2013 6:02 am
by social_experiment
The syntax below should be amended like the example below; currently your option tags have no values which might be causing your problems. Stick to use single quotes for $_POST values like you did with $_POST['pid'].

Code: Select all

<option  value="<?php echo $size_4?>"><?php echo $size_4?></option>
// should be
<option  value="<?php echo $size_4; ?>"><?php echo $size_4; ?></option>