I explain you my problem. In my form, a part of the inputs are directly written in the html code, while another part is written in php in a condition (which here is true).
When I send the form and I var_dump
the variable $_POST
, only the data of the inputs written in the HTML have been sent.
On the other hand, it is impossible to retrieve the data of the inputs written in the PHP condition.
Do you understand why I have this problem? don't hesitate to let me know if you need more details Thanks for your help.
<form action="php/addcart.php" method="post">
<?php if(!empty($kitShortDesc)) : ?> // Variable is not empty
<div class='product-associates' style='margin-bottom: 20px;'>
<div class='product-associates-checkbox'>
<input type='hidden' name='cartContent[name][kit]' value='<?php echo kit;?>'/>
<input type='checkbox' name='cartContent[name][kit][kitShortDesc]' value='<?php echo $kitShortDesc;?>'>
<input type='hidden' name='cartContent[name][kit][kitLongDesc]' value='<?php echo $kitLongDesc;?>'>
<input type='hidden' name='cartContent[name][kit][kitPrice]' value='<?php echo $kitPrice;?>'>
</div>
<div class='product-associates-container'>
<p>Kit Embrayage : <?php echo $kitShortDesc;?></p>
<p>Prix : <?php echo $kitPrice;?>€</p>
<a class='product-associates-learnmore' href=''>En savoir plus</a>
</div>
</div>
<?php endif; ?>
<input type='hidden' name='cartContent[name]' value='<?php echo $name;?>'/>
<input type='hidden' name='cartContent[name][brand]' value='<?php echo $brand;?>'/>
<input type='hidden' name='cartContent[name][model]' value='<?php echo $model;?>'/>
<input type='hidden' name='cartContent[name][category]' value='<?php echo $category;?>'/>
<input type='hidden' name='cartContent[name][price]' value='<?php echo $price;?>'/>
<div >
<input type="submit" value="Ajouter au panier">
</div>
</form>
result of var_dump($_POST['cartContent'])
in addcart.php
:
array(1) { ["name"]=> array(4) { ["brand"]=> string(4) "Audi" ["model"]=> string(2) "A1" ["category"]=> string(8) "1.2 TFSI" ["price"]=> string(3) "400" } }
As you can see, there is no array [kit]
CodePudding user response:
Issue identified. This following line should be at the top position just after the FORM declaration.
<input type='hidden' name='cartContent[name]' value='<?php echo $name;?>'/>