php - how to pass option value into hidden field -


i keep notice: undefined index: color how can pass value text box? have try defind $size = ""; still not working

        echo '<div class="product-desc">select 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>'; 

you getting undefined index: color because $_post['color'] not set unless form posted. can add check print value in $_post['color'] if set, else print empty string

try this

echo '<input type="text" name="color" value="'. isset($_post['color']) ? $_post['color'] : '' .'" />'; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -