使用php进行表单验证页面

时间:2015-09-07 18:17:09

标签: php jquery

我正在尝试创建一个简单的页面,用户可以在之前的HTML表单上单击“提交”后看到他的格式化输入(在应该发送的电子邮件中的样子)

由于我还希望将此网站与格式化的表单数据一起用作6种不同表单的最终“手动验证”点,因此只有在用户点击提交按钮时,才会发送包含表单中所有数据的电子邮件。这个网站只是。

我在此网站上显示用户输入没有任何问题,但是,似乎我对变量存在范围问题。

我正在显示提交按钮的if语句,如果显示来自上一站点的用户输入。但是,即使将$ content声明为全局内容,它仍然是空的。也许这也是因为另一个if语句这次没有运行。

有没有办法在另一个if语句中使用$ content?还是有一个更漂亮的解决方案?

我对php很新,这是我尝试的第一个php项目,所以非常感谢一些输入。

<?php
require ('/scripts/PHPMailer-master/PHPMailerAutoload.php');

if (isset($_POST['new_mailbox']))
{
    // new Mail Form Data
    $Name_Applicant                     = $_POST['Name_Applicant'];
    $FirstName_Applicant                = $_POST['First_Name_Applicant'];
    $email_Applicant                    = $_POST['email_Applicant'];
    $Telephone_Applicant                = $_POST['Telephone_Applicant'];

    $head = "<h1>Please check your data before submitting the request</h1>";
    $part_one = "
        <table class=\"pdf_table\" border=\"1\">
        <tr><td class=\"table_header\" colspan=\"2\"><b><u>Applicant</u></b></td></tr>
        <tr class=\"odd\"><td class=\"first\">Name:</td><td>".$Name_Applicant."</td></tr>
        <tr class=\"even\"><td class=\"first\">First Name:</td><td>".$FirstName_Applicant."</td></tr>
        <tr class=\"odd\"><td class=\"first\">eMail:</td><td>".$email_Applicant."</td></tr>
        <tr class=\"even\"><td class=\"first\">Telephone Number:</td><td>".$Telephone_Applicant."</td></tr>
        </table>";
$part_two = "";

echo $head;
    if (isset($part_one)){$content.=$part_one;}
    if (isset($part_two)){$content.=$part_two;}
    if (isset($part_three)){$content.=$part_three;}
    if (isset($part_four)){$content.=$part_four;}
    if (isset($content)){echo $content;}

echo "
<form method=\"POST\">
    <input name=\"form_eMail8\" type=\"hidden\">
    <input name=\"form_OK\" type=\"submit\" value=\"OK\">
</form>
";
}

if(isset($_POST["form_OK"]))
    {
        $CSS = file_get_contents('form.css');
        $html = '<style>'.$CSS.'</style>';          
        $html .= "{$content}";  
}
?>

1 个答案:

答案 0 :(得分:0)

当你说:

时,我认为你是对的
  

也许这也是因为另一个if语句这次没有运行。

您需要执行填充$content的代码,以便在两种情况下运行。

也许是这样的:

<?php
require ('/scripts/PHPMailer-master/PHPMailerAutoload.php');

// new Mail Form Data
$Name_Applicant                     = $_POST['Name_Applicant'];
$FirstName_Applicant                = $_POST['First_Name_Applicant'];
$email_Applicant                    = $_POST['email_Applicant'];
$Telephone_Applicant                = $_POST['Telephone_Applicant'];

$head = "<h1>Please check your data before submitting the request</h1>";
$part_one = "
    <table class=\"pdf_table\" border=\"1\">
    <tr><td class=\"table_header\" colspan=\"2\"><b><u>Applicant</u></b></td></tr>
    <tr class=\"odd\"><td class=\"first\">Name:</td><td>".$Name_Applicant."</td></tr>
    <tr class=\"even\"><td class=\"first\">First Name:</td><td>".$FirstName_Applicant."</td></tr>
    <tr class=\"odd\"><td class=\"first\">eMail:</td><td>".$email_Applicant."</td></tr>
    <tr class=\"even\"><td class=\"first\">Telephone Number:</td><td>".$Telephone_Applicant."</td></tr>
    </table>";
$part_two = "";

if (isset($part_one)){$content.=$part_one;}
if (isset($part_two)){$content.=$part_two;}
if (isset($part_three)){$content.=$part_three;}
if (isset($part_four)){$content.=$part_four;}
if (isset($content)){echo $content;}

if (isset($_POST['new_mailbox']))
{
echo $head;

echo "
<form method=\"POST\">
    <input name=\"form_eMail8\" type=\"hidden\">
    <input name=\"form_OK\" type=\"submit\" value=\"OK\">
</form>
";
}

if(isset($_POST["form_OK"]))
{
    $CSS = file_get_contents('form.css');
    $html = '<style>'.$CSS.'</style>';          
    $html .= "{$content}";  
}
?>