这是html..。
<form name="stream" method="post" action="scripts/validate.php">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="attend" value="yes" autocomplete="off">
<label class="form-check-label" for="attend">Yes, I will attend the event in Edo State.</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="trad" value="yes" autocomplete="off">
<label class="form-check-label" for="trad">Yes, I'm interested in getting the Asoebi.</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="house" value="yes" autocomplete="off">
<label class="form-check-label" for="house">Yes, I am interested in getting Accommodation.</label>
</div>
<button class="btn bg-bur text-white h4 btn-block mt-20" type="submit" name="stream">Submit</button>
</form>
下面是处理表单数据的php,但它仍然显示相同的结果“我想要完整的注册”,即使选中了1个复选框或没有选中任何复选框。
<?php
if( isset( $_POST['stream'] ) ) {
if ($_POST['attend'] == 'yes' && $_POST['trad'] == 'yes' && $_POST['house'] == 'yes' ) {
echo "I want the full registration";
}
elseif ($_POST['attend'] == 'yes' && $_POST['trad'] == 'yes' && $_POST['house'] !== 'yes' ) {
echo "I want the Asoebi and I will attend";
}
elseif ($_POST['attend'] == 'yes' && $_POST['trad'] !== 'yes' && $_POST['house'] !== 'yes' ) {
echo "I am only attending";
}
elseif ($_POST['attend'] !== 'yes' && $_POST['trad'] == 'yes' && $_POST['house'] !== 'yes' ) {
echo "I only want Asoebi";
}
elseif ($_POST['attend'] !== 'yes' && $_POST['trad'] !== 'yes' && $_POST['house'] !== 'yes' ) {
echo "You haven't selected anything";
}
}
?>
https://stackoverflow.com/questions/50768840
复制相似问题