php联系表格,谢谢你的页面

时间:2013-01-31 12:38:08

标签: php

以下是我的php联系表格:

页面用户输入信息:

<div style="padding-left: 50px">
<p class="arial"><strong></strong><br /><br /></p>
<form action="freecontact2formprocess.php" method="post"> 
<table class="freecontact2form" border="0" width="400px">
<tbody>
<tr>
<td colspan="2"><span style="font-size: x-small;"> </span> <font color=#E42217 >Please ensure all card details are correct.</font>
  <br /><br /></td>
</tr>
<tr>
  <td valign="top"><table width="400px" class="freecontact2form">
    <tr>
      <td colspan="2"><br />
        <br />
        <div class="freecontact2formmessage"> </div></td>
    </tr>
    <tr>
  <td valign="top"><label for="subject_type" >Subject Type:<span class="required_star"> * </span></label></td>
  <td valign="top"><select name="subject_type" id="subject_type">
    <option selected="selected" value ="Maths">Maths</option>
    <option value ="English">English</option>
    <option value ="Biology">Biology</option>
    <option value ="Chemistry">Chemistry</option>
    <option value ="Physics">Physics</option>
    <option value ="History">History</option>
  </select></td>
</tr>


<tr>
  <td style="text-align:center" colspan="2"><br /><br /> <input src="../../images/submit1.png" name="submit" type="image"> <br /><br /> <!--      If you want to remove this author link,     please purchase an unbranded version from: http://www.freecontact2form.com/unbranded_form.php       Or upgrade to the professional version at: http://www.freecontact2form.com/professional.php     --> <br /><br /></td>
</tr>
  </table></td>
  <td valign="top">&nbsp;</td>
</tr>


</tbody>
</table>
</form> <br />
<p> </p>
<p> </p>

这是freecontact2formprocess.php:

if(isset($_POST['subject_type'])) {

    include 'freecontact2formsettings.php';

function died($error) {
    echo "Sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}

if(!isset($_POST['subject_type']) ||
    !isset($_POST['testvariablealwaysset']) ||


    ) {
    died('Sorry, there appears to be a problem with your form submission.');        
}

$subjecttype_from = $_POST['subject_type']; // required









$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>

这是freecontact2formsettings:

<?php

$email_to = "myemailaddress@emailaddress.com"; // your email address
$email_subject = "Subject type"; // email subject line


if ($subjecttype_from="Maths")
{
$thankyou = "http://www.google.com";
}
else
{
$thankyou = "http://www.yahoo.com"; // thank you page
}

// if you update the question on the form -
// you need to update the questions answer below
$antispam_answer = "25";

?>

在freecontact2formsetting文件中,我设置了一个条件,如果用户从下拉菜单中选择数学,感谢页面将设置为google.com,如果选择其他任何内容,则会转到yahoo.com。目前所有重定向都将转到google.com,我如何确保当用户选择除数学之外的任何内容时,它会转到yahoo.com?

1 个答案:

答案 0 :(得分:0)

您要分配而不是评估,将您的if声明更改为:

if ($subjecttype_from == "Maths")

您也可以这样写:

$thankyou = ($subjecttype_from == "Maths") ? 'http://www.google.com' : 'http://www.yahoo.com';

通过查看代码,在评估$subjecttype_from语句时未定义if。在包含进行比较的文件之前分配变量,例如:

$subjecttype_from = $_POST['subject_type']; // required
include 'freecontact2formsettings.php';