Q:

how to pass option value into hidden field

I keep get Notice:  Undefined index: color 
How can i pass the value into the text box?
I have try defind $size = ""; but it still not working
        echo '<div class="product-desc">Select Your Size 
        <select name="size" id="size">
        <option value="5">5</option>
         <option value="5.5">5.5</option>
          <option value="6">6</option>
          <option value="6.5">6.5</option>
          </select></div>';
          echo '<div class="product-desc">Select Color 
        <select name="color" id="color" >
        <option value="red">Red</option>
         <option value="blue">Blue</option>
          <option value="black">Black</option>
          <option value="green">Green</option>
          <option value="pink">Pink</option>
          </select></div>';
        echo '<div class="product-info">';
        echo 'Price '.$currency.$obj->price.'<br />';
        echo 'Qty <input type="text" name="product_qty" value="1" size="3" />';
        echo '<button class="add_to_cart" style="border-color:#F60"><img src="image/addcart.png" alt="addcart" width="120" height="25" align="middle" /></button>';
        echo '<a href="view_product.php?id=' . $obj->id . '"><img src="image/viewproduct.png" width="120" height="30" align="middle" /></a>';
        echo '</div></div>';
        echo '<input type="hidden" name="type" value="add" />';
        echo '<input type="text" name="color" value="'.$_POST['color'].'" />';
        echo '<input type="text" name="size" value="'.$_POST['size'].'" />';
        echo '<input type="hidden" name="id" value="'.$obj->id.'" />';
        echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
        echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
        echo '</form>';
        echo '</div>';

A:

you are getting Undefined index: color because your $_POST['color'] is not set unless the form is posted. you can add a check to print the value in $_POST['color'] if it is set, else print empty string
try this
echo '<input type="text" name="color" value="'. isset($_POST['color']) ? $_POST['color'] : '' .'" />';

