我有一个输入字段,用于保存项目的数量。如果用户更改数量值,我想更新会话中存储的值。我的问题是我无法获得"值"。
<form method="post">
<input type="number" class="form-control text-center" name="quantityInput" size="1" maxlength="2" value="'.$cart_itemDisplay['quantity'].'">
<button class="btn btn-info btn-sm" method="POST" name="refreshBtn"><i class="fa fa-refresh"></i></button>
</form>
当我尝试存储值时:
$quantityOfItemToAdjust = $_POST['quantityInput'];
完整代码:
echo '
<tbody>
<tr>
<td data-th="Product">
<div class="row">
<div class="col-sm-2 hidden-xs"><img src="img/movies/'.$imageName.'" alt="..." class="img-responsive"/></div>
<div class="col-sm-10">
<h4 class="nomargin">'.$nameOfProduct.'</h4>
<p>'.$productDesc.'</p>
</div>
</div>
</td>
<td data-th="Price">£'.$priceOfItem.'</td>
<td data-th="Quantity">
<form method="post" action="tickets.php">
<input type="number" class="form-control text-center" name="quantityInput" size="1" maxlength="2" value="'.$cart_itemDisplay['quantity'].'">
</form>
</td>
<td data-th="Subtotal" class="text-center">1.99</td>
<td class="actions" data-th="">
<form method="post" action="tickets.php">
<button class="btn btn-info btn-sm" method="submit" name="refreshBtn"><i class="fa fa-refresh"></i></button>
<input name="item_to_adjust" type="hidden" value="'.$idOfItem.'"/>
<button class="btn btn-danger btn-sm"><i class="fa fa-trash-o"></i></button>
</form>
</td>
</tr>
</tbody>
';
答案 0 :(得分:1)
您应该使用提交而不是按钮,表单需要操作。
<form method="post" action="yourpage.php">
<input type="number" class="form-control text-center" name="quantityInput" size="1" maxlength="2" value="'.$cart_itemDisplay['quantity'].'">
<input type="submit" class="btn btn-info btn-sm" name="refreshBtn" value="Refresh">
</form>
这应该有用。