我确信这很简单
在按下提交按钮后如何编写php脚本,以便选中复选框。它不是必需的,但仍然希望能够在这里选择我的代码
<?php
($_POST['submit']) {
{
?>
<section id="contact">
<div class="container">
<form method="post" action="#" role="form">
<div class="row">
<div class="col-md-6 offset-md-3">
<h1>Office Cleaning</h1>
<?php echo $result;?>
<p>Please fill out form below</p>
</div>
<div class="col-md-6 offset-md-3">
<div id="options" style="margin-left:-20.5px">
<div class="form-check form-check-inline">
<label class="form-check-label">
<input type="checkbox" value="MDO" name="type"> Medical Office
</label>
</div>
<div class="form-check form-check-inline">
<label class="form-check-label">
<input type="checkbox" value="IDO" name="type"> Industrial Office
</label>
</div>
<div class="form-check form-check-inline">
<label class="form-check-label">
<input type="checkbox" value="SO" name="type"> Standard Office
</label>
</div>
</div>
</from>
答案 0 :(得分:0)
如果在您的复选框输入中嵌入内联,这是一个简单的
<input type="checkbox" value="MDO" name="type[]" <?php if(isset($_POST['type']) && in_array('MD0', $_POST['type'])){ echo 'checked="checked"; } ?> > Medical Office
请注意从name="type"
到name="type[]"
的更改,因为您要创建数组而不只是获取最后一个输入