表单数据出错,尝试使用PHP进行验证

时间:2011-07-29 14:44:46

标签: php forms joomla validation

所以我在页面上有这个表单并试图用PHP验证值,然后关闭电子邮件。我也在使用Joomla CMS。表单提交但没有值传输。有没有人对正在发生的事情有任何建议或想法?提前谢谢。

http://www.indigoeastend.com/same-sex-weddings

    <?php echo ''; //error_reporting(E_ALL & ~E_DEPRECATED); ?>
    <?php flush(); ?>
    <table style="margin-top:1.2em;">
    <tr>
    <td class="wedding_left">
    <p style="margin-top:0;">New York has said "I do" to same-sex marriage and for your New York wedding choose Hotel Indigo. Here you'll experience all the beauty that can be found on Long Island's famous East End. Right next door to vineyards, beaches the North Fork and the Hamptons we can provide a multitude of wedding event options. Our newly designed hotel offers a chic, contemporary and cosmopolitan setting that will set the stage for your ideal affair.  Hotel Indigo provides a boutique private experience hosting only one wedding at a time–yours.</p>

    <p>Our wedding planner will work with you to create a completely custom event in our exquisitely appointed ballroom or create a tented outdoor space by fascinating poolscape and cabanas. Hotel Indigo features stunning landscapes for photography and stylish areas for your guests to gather and enjoy themselves.</p>

    <p>Our catering team can provide you with a custom menu serving your favorite dishes and signature drinks. We can arrange your beach excursions, wine tours and spa treatments so you and your guests can truly appreciate the NY wedding of your dreams on the East End.</p>
    </td>
    <td class="wedding_right">

    <h1 style="word-spacing:-.15em; margin:0 0 5px 0 !important; font-size:1.5em;">TOUR FOR THE DAY &<br />
    STAY FOR THE NIGHT!</h1>
    <p style="margin-top:0;">
    <b style="color:#1f407e;">Come tour the hotel as a possible venue for your upcoming wedding and receive 
    a free overnight stay*</b>

    <p>Please provide the following information:</p>

    <?php
    $good_to_go = 0;

    if(isset($_POST['first_name'])) {
        $first_name = $_POST['first_name'];
    } else {
        $first_name = '';
    }

    if(isset($_POST['last_name'])) {
        $last_name = $_POST['last_name'];
    } else {
        $last_name = '';
    }

    if(isset($_POST['email'])) {
        $email = $_POST['email'];
    } else {
        $email = '';
    }

    if(isset($_POST['phone'])) {
        $phone = $_POST['phone'];
    } else {
        $phone = '';
    }

    if(isset($_POST['submitIt'])) {
        $submitIt = $_POST['submitIt'];
    } else {
        $submitIt = 0;
    }

    echo 'NAME: '.$first_name.' ';
    echo $last_name.'<br />';
    echo 'EMAIL: '.$email.'<br />';
    echo 'PHONE: '.$phone.'<br />';

    if($submitIt == 1) {
            echo 'WORKS!';
        if ($first_name == '' && $last_name == '' && $email == '' && $phone == '') {
            echo "<p class='red'  style='color:red;'>ERROR: Please fill the form out before submitting it.</p>";
            $good_to_go = 0;
        } elseif ($first_name == '' || $last_name == '' || $email == '' || $phone == '') {
            if($first_name == '') {
                echo "<p class='red no_margin' style='color:red;'>ERROR: Please enter your first name.</p>";
                //$good_to_go = 0;
            }

            if($last_name == '') {
                echo "<p class='red no_margin' style='color:red;'>ERROR: Please enter your last name.</p>";
                //$good_to_go = 0;
            }

            if($phone == '') {
                echo "<p class='red no_margin' style='color:red;'>ERROR: Please enter a phone number.</p>";
                //$good_to_go = 0;
            }

            if(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
                echo "<p class='red no_margin' style='color:red;'>ERROR: Please enter a valid e-mail.</p>";
                //$good_to_go = 0;
                $email = '';
            }
        } else {
            if(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
                echo "<p class='red' style='color:red;'>ERROR: Please enter a valid e-mail.</p>";
                //$good_to_go = 0;
            } else {
                //send that puppy!
                $mydate = date ( 'l, F d Y g:i A',time()+240 );

                $to = 'drottino@viridian-graphics.com';

                //e-mail subject
                $subject = 'Someone has submitted a form via the website';

                //e-mail message
                $message = "I am interested in the hotel tour.\r\n\r\n\r\n"

                //."Subject: $contact_subject\r\n"
                ."<b>SUBMITTED ON:</b> ".$mydate."\r\n"
                //."<b>FROM IP:</b> {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
                ."<b>CONTACT NAME:</b> ".$first_name." ".$last_name."\r\n"
                ."<b>MESSAGE:</b> ".$message."\r\n\n";
                //."<b>FORM ADDRESS:</b> {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";

                $headers = "From: $first_name $last_name <$email>\n"
                ."Reply-To: ".strip_tags($email)."\n"
                ."MIME-Version: 1.0\r\n"
                ."Content-Type: text/html; charset=ISO-8859-1\r\n";

                $good_to_go = 1;
            }
        }
    } else {

    }
    ?>

    <?php if ($good_to_go == 0) { ?>
        <form method="post" action="http://www.indigoeastend.com/same-sex-weddings">
            <p><label for="first_name">FIRST NAME</label><br />
            <input type="text" size="30" name="first_name" value="<?php echo $first_name; ?>" /></p>

            <p><label for="last_name">LAST NAME</label></br >
            <input type="text" size="30" name="last_name" value="<?php echo $last_name; ?>" /></p>

            <p><label for="email">E-MAIL ADDRESS</label><br />
            <input type="text" size="30" name="email" value=""/></p>

            <p><label for="phone">PHONE NUMBER</label><br />
            <input type="text" size="30" name="phone" value="<?php echo $phone; ?>" /></p>

            <input type="hidden" value="1" name="submitIt">
            <input class="button" type="submit" value="Send" /></p>
        </form>
    <?php } else
            //mail($to, $subject, $message, $headers); ?>
        <p>Thank you for submitting your request. We will get back to you shortly.</p>
    <?php } ?>

    <p>Subject to a one hour tour of the<br />
    hotel, advance notice required for<br />
    tour and stay offer.</p>

    <p>*Valid for any 1 night stay sunday–thursday and subject to availability.</p>
    <hr />
    </p>Speak with our wedding planners<br />
    to plan your unique affair<br />
    631.369.2200 | dmazza@eastendhotels.com<br />
    <a href="mailto:dmazza@eastendhotels.com">contact us</a></p>

    <p>Ballroom for up to 240 guests<br />
    Outdoor Tented Space<br />
    Gazebo for ceremonies<br />
    Stylishly furnished Poolscape<br />
    Restaurant & Private Dining Room for rehearsal dinners and brunches<br />
    After-parties<br />
    Transportation planning services<br />
    Hospitality areas<br />
    Bridal Suite & Guest accommodations</p>
    </td>
    </tr>
    </table>

1 个答案:

答案 0 :(得分:1)

问题出在142行..在这里,你错过了{在别的地方。它应该是:

<?php } else {
            //mail($to, $subject, $message, $headers); ?>
        <p>Thank you for submitting your request. We will get back to you shortly.</p>
    <?php } ?>

我确实运行了代码,它运行正常,我可以获得提交的值,例如

NAME: asdf sasa
EMAIL: asdf@deded.com
PHONE: 123
WORKS!

Thank you for submitting your request. We will get back to you shortly