我有一个带有if / else语句的表单,我得到了第一部分工作。它是电影评级的单选按钮。如果没有字段为空,则打印信息。但我需要插入另一个回声,具体取决于他们是否表示希望联系调查,我不知道在哪里放置代码。见下文:
<fieldset><legend>MOVIE WATCHED AND RATING SURVEY:</legend>
Please tell us your name: <input type="text" name="name" value="<?php echo $name;?>">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
Please tell us your email address: <input type="text" name="email" value="<? php echo $email;?>">
<span class="error">* <?php echo $emailErr;?></span>
<br><br>
Name one movie you watched recently: <input type="text" name="movie" value="<?php echo $movie;?>">
<span class="error">* <?php echo $movieErr;?></span>
<p><label>Please rate the movie:</label></p>
<form action="" method="post">
<input type="radio" name="rating" value="Very Bad" checked> Very Bad<br>
<input type="radio" name="rating" value="Bad"> Bad<br>
<input type="radio" name="rating" value="Middle-of-the-Road"> Middle of-the-Road<br>
<input type="radio" name="rating" value="Good"> Good<br>
<input type="radio" name="rating" value="Very Good"> Very Good<br>
</form>
<p><label>Would you like to be contacted again for addtional surveys?</label></p>
<form action="" method="post">
<input type="radio" name="survey" value="yes" checked> Yes<br>
<input type="radio" name="survey" value="no"> No<br>
</form>
<p align="center"><input type="submit" name="submit" value="Submit My Information" /></p>
</fieldset>
</form>
<?php # Program 2 Handle form
// Print the submitted information:
if ( !empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['movie']) ) {
echo "Thank you for completing the survey. Here's what you said";
echo "<p>Your name is {$_POST['name']}";
echo "<p>Your e-mail address is {$_POST['email']}";
echo "<p>You recently watched {$_POST['movie']} and felt it was {$_POST['rating']}!";
echo "<p>Thank you for agreeing to be contacted for future surveys";
} else { // Missing form value.
echo '<p>Please go back and fill out all required fields.</p>';
}
?>
这是我迷失的地方。我需要说&#34;感谢您同意接受调查&#34;或者&#34;我们尊重你不希望&#34;根据他们在单选按钮上输入是或否的内容
答案 0 :(得分:0)
根据你的问题,我认为你想要。
if(isset($_GET["submit"]))
{
if(isset($_GET["addtional_surveys"])){
if($_GET["addtional_surveys"]=="Yes"){
//show your additional survey form here
}else{
//movie extra details
}
}else{
//your form code goes here <form action="" method="get">
}
}else{
//your form code goes here <form action="" method="get">
}
&GT;
答案 1 :(得分:0)
首先,您的HTML需要一些工作。如果所有这些信息都应该一起提交,那么您应该只有一个 filter_all
标记,如下所示:
<form>
然后在PHP中,添加<form action="" method="post">
<fieldset><legend>MOVIE WATCHED AND RATING SURVEY:</legend>
<label for="name">Please tell us your name:</label>
<input type="text" name="name" value="<?php echo $name ?>">
<span class="error">* <?php echo $nameErr ?></span>
<br><br>
<label for="email">Please tell us your email address: </label>
<input type="text" name="email" value="<?php echo $email ?>">
<span class="error">* <?php echo $emailErr ?></span>
<br><br>
<label for="movie">Name one movie you watched recently: </label>
<input type="text" name="movie" value="<?php echo $movie ?>">
<span class="error">* <?php echo $movieErr ?></span>
<p><label for="rating">Please rate the movie:</label></p>
<input type="radio" name="rating" value="Very Bad" checked> Very Bad<br>
<input type="radio" name="rating" value="Bad"> Bad<br>
<input type="radio" name="rating" value="Middle-of-the-Road"> Middle of-the-Road<br>
<input type="radio" name="rating" value="Good"> Good<br>
<input type="radio" name="rating" value="Very Good"> Very Good<br>
<p>
<label for="survey">
Would you like to be contacted again for addtional surveys?
</label>
</p>
<input type="radio" name="survey" value="yes" checked> Yes<br>
<input type="radio" name="survey" value="no"> No<br>
<p align="center">
<input type="submit" name="submit" value="Submit My Information" />
</p>
</fieldset>
</form>
选项的检查将非常简单:
survey
答案 2 :(得分:0)
我认为您可以从使用HTML5中受益。 HTML5会在提交表单时自动为您提供回复。您可以在输入的末尾放置“必需”。你也不需要过滤,例如。不再发送电子邮件,HTML 5即时执行此操作。您可以在W3schools.com上找到更多相关信息。在您的表单部位:
<input type="text" name="movie" size="40" maxlength="60" />
<select name="rating" size="3">
<option>Vælg</option>
<option value="0">Very Bad</option>
<option value="1">Bad</option>
<option value="2">Middle-of-the-Road</option>
<option value="3">Good</option>
<option value="4">Very Good</option>
</select>
<p><label>Would you like to be contacted again for addtional surveys? </label></p>
<input type="radio" name="status" value="YES" checked="checked" />
<input type="radio" name="status" value="NO" />
在接收php脚本的地方:
<?php # Program 2 Handle form
// Print the submitted information:
if ( !empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['movie']) ) {
echo "Thank you for completing the survey. Here's what you said";
echo "<p>Your name is {$_POST['name']}";
echo "<p>Your e-mail address is {$_POST['email']}";
echo "<p>You recently watched {$_POST['movie']} and felt it was {$_POST['rating']}!";
if ($_POST['status']=='YES') {
// respondent would like you to come back
echo "<p>Thank you for agreeing to be contacted for future surveys";
}else{
// respondent does not want to particcipate in future surveys
echo "<p>We respect your wish not to be contacted in the future";
}
}else{ // Missing form value.
echo '<p>Please go back and fill out all required fields.</p>';
}
我没有对此进行测试,但它应该可行。