0

我有这个表格:

<form action="../index_success.php" method="post" id="sendEmail" class="email">
            <h3 class="register2">Newsletter Signup:</h3>
            <ul class="forms email">
                <li class="name">
                    <label for="yourName">Name: </label>
                    <input type="text" name="yourName" class="info" id="yourName" value="<?php echo $_POST['yourName']; ?>" /><br />
                </li>
                <li class="city"><label for="yourCity">City: </label>
                    <input type="text" name="yourCity" class="info" id="yourCity" value="<?php echo $_POST['yourCity']; ?>" /><br />
                </li>
                //This is where I need help with the check box code
                <li class="classes"><label for="classInterest">Interested in classes?: </label>
                    <input type="checkbox" name="classInterest" class="info" id="classInterest" value="Yes" /><br />
                </li>
                <li class="email">
                    <label for="emailFrom">Email: </label>
                    <input type="text" name="emailFrom" class="info" id="emailFrom" value="<?php echo $_POST['emailFrom']; ?>" />
                     <?php if(isset($emailFromError)) echo '<span class="error">'.$emailFromError.'</span>';

                     ?>
                </li>
                <li class="buttons email">
                     <button type="submit" id="submit">Send</button>
                     <input type="hidden" name="submitted" id="submitted" value="true" />
                </li>
            </ul>
        </form>

这是通过电子邮件发送给用户的。我不知道如何添加上面的复选框,因此如果选中该框,用户会看到“是”:

<?php 
$mailTo = 'xxx@xxx.com'; // This is the hardcoded Recipient Address 
$mailSubject = 'Subject'; // This is the hardcoded Subject
$mailFrom = $_POST['emailFrom']; 
$yourName = $_POST['yourName']; 
$yourCity = $_POST['yourCity'];
$classInterest = $_POST['classInterest'];  //This is the code for the checkbox

$mailHeader = "From: {$mailFrom}"; 
$mailBody = "Name = {$yourName} City = {$yourCity} Class interest = {$classInterest}";

mail( $mailTo , $mailSubject , $mailBody , $mailHeader );

基本上,我需要的是(psudocode):

if ($classInterest == "yes") {
   $classInterest = "Interested in Classes in ".$yourCity;
}
else {
...
}
4

1 回答 1

2

尝试这个:

$classInterest = (isset($_POST['classInterest']) && $_POST['classInterest'] == 'Yes') ? "Interested in Classes in " . $yourCity : '';

编辑

http://blog.gerv.net/2006/10/firefox_reload_behaviour/阅读 Jason 的文章和第一条评论

于 2012-11-26T05:27:06.513 回答