Php 仅当选中此框时发送当前日期
我在PHP中有一个crud系统,并创建了一个审批部分。我已经为产品创建了一个审批页面,如果选中该框,该页面将非常有效。但如果不是,并且该人填写了表格,则仍然输入了日期。如果勾选了该框,我怎么能让它只输入日期 这是表格Php 仅当选中此框时发送当前日期,php,html,mysql,Php,Html,Mysql,我在PHP中有一个crud系统,并创建了一个审批部分。我已经为产品创建了一个审批页面,如果选中该框,该页面将非常有效。但如果不是,并且该人填写了表格,则仍然输入了日期。如果勾选了该框,我怎么能让它只输入日期 这是表格 // if the form was submitted if($_POST){ $product->reviewed = $_POST['reviewed']; $product->review_date = $_POST['review_date'
// if the form was submitted
if($_POST){
$product->reviewed = $_POST['reviewed'];
$product->review_date = $_POST['review_date'];
// set product property values
// update the product
if($product->approve()){
echo "<div class='alert alert-success alert-dismissable'>";
echo "Product approvals were set.";
echo "</div>";
}
// if unable to update the product, tell the user
else{
echo "<div class='alert alert-danger alert-dismissable'>";
echo "Unable to approve product.";
echo "</div>";
}
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"] . "?id={$id}");?>" method="post">
<table class='table table-hover table-responsive table-bordered'>
<tr>
<td>Name</td>
<td><?php echo $product->name; ?></td>
</tr>
<tr>
<td>Review</td>
<td><?php
if (is_null($product->reviewed)){
?>
<div id="ck-button"><label><input type="checkbox" name="reviewed" value="<?php echo $userRow['user_name'];?>" id="checkbox"/><span>Approve</span>
<input type='hidden' name='review_date' class='form-control' value="<?php echo date("Y-m-d h:i:sa"); ?>"/>
</div> </label>
<?php ;
}elseif (isset($product->reviewed)){
echo "<div id='approved-button'>" . $product->reviewed . ", " . $product->review_date . "</div>";
}
?>
</td>
</tr>
<tr>
<td></td>
<td>
<button type="submit" class="btn btn-primary">Set Approvals</button>
</td>
</tr>
</table>
</form>
要检查是否已在PHP中“选中”复选框元素,请执行以下操作:
if(isset($_POST['myCheckbox'])) { ... }
相反,你有
if($_POST) { ... }
如果我正确理解了你的问题,这就是你的问题所在。在第二个问题中,你的结束标记不匹配。您正在关闭外部,然后我将添加更多批准按钮。我不希望它不发布任何东西,因为其中一个没有检查。我只是不希望它发布日期,除非选中该框。或者,您是否建议在另一个框的上方添加另一个if。如果您希望使用其他数据并有条件地设置复选框数据,那么您仍然可以使用上述相同的功能。设置值时,选中并确保选中复选框。如果是,则设置值,如果不是,则不设置值。我尝试添加此项,但无效。仍然添加日期。ifisset$\u POST['Revied']{$product->review_date=$\u POST['review_date'];$product->Revied=$\u POST['Revied']}成功地使它与这个'ifisset$\u POST['Revied']{$product->review_date=$\u POST['review_date'];$product->Revied=$\u POST['Revied']一起工作!isset$_POST['review']{unset$_POST['review_date']}`
if($_POST) { ... }