Javascript 预订过程中出现PHP表单错误

Javascript 预订过程中出现PHP表单错误,javascript,php,html,email,Javascript,Php,Html,Email,我有一位客户希望使用预订页面。这个过程只是将联系信息通过电子邮件发送给我自己。我一直是一名.NET开发人员,从未使用过PHP。我做了很多研究,并试图创建一个booking.php页面。由于代码与现有联系人页面非常相似(该页面正在运行),因此我从contact.php复制了代码,将其保存到booking.php,并根据自己的想法调整了代码。我已经把代码贴在下面了。我收到的错误消息是输入了有效的电子邮件地址。由于电子邮件(html/php)的代码与联系人页面相同,而且我实际上使用的是有效的电子邮件,

我有一位客户希望使用预订页面。这个过程只是将联系信息通过电子邮件发送给我自己。我一直是一名.NET开发人员,从未使用过PHP。我做了很多研究,并试图创建一个booking.php页面。由于代码与现有联系人页面非常相似(该页面正在运行),因此我从contact.php复制了代码,将其保存到booking.php,并根据自己的想法调整了代码。我已经把代码贴在下面了。我收到的错误消息是输入了有效的电子邮件地址。由于电子邮件(html/php)的代码与联系人页面相同,而且我实际上使用的是有效的电子邮件,因此我对如何调试感到非常困惑:/。如果有人有任何建议,我将不胜感激

正如您在下面看到的,我只是尝试为新字段创建变量,还没有将它们包含在我的电子邮件正文中。我正计划在我处理完这个问题后再谈这个问题

<?php

            if(!$_POST) exit;

            // Email address verification, do not edit.
            function isEmail($email) { 
                return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));     
            }

            if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");

            $name     = $_POST['name'];
            $email    = $_POST['email'];
            $phone   = $_POST['phone'];
            $address   = $_POST['address'];
            $city   = $_POST['city'];
            $state   = $_POST['state'];
            $zip   = $_POST['zip'];
            $duration   = $_POST['duration'];
            $people   = $_POST['people'];

            if(trim($name) == '') {
                echo '<div class="error_message box-red box">Attention! You must enter your name.</div>';
                exit();
            } 


              else if(trim($email) == '') {
                echo '<div class="error_message box-red box">Attention! Please enter a valid email address.</div>';
                exit();
            }


            else if(trim($phone) == '') {
                echo '<div class="error_message box-red box">Attention! Please enter a valid phone number.</div>';
                exit();
            }   
              else if(trim($address) == '') {
                echo '<div class="error_message box-red box">Attention! Please enter a valid address.</div>';
                exit();
            }
              else if(trim($city) == '') {
                echo '<div class="error_message box-red box">Attention! Please enter a valid city.</div>';
                exit();
            }

              else if(trim($state) == '') {
                echo '<div class="error_message box-red box">Attention! Please enter a valid state.</div>';
                exit();
            }

              else if(trim($zip) == '') {
                echo '<div class="error_message box-red box">Attention! Please enter a valid zip.</div>';
                exit();
            }

              else if(trim($duration) == '') {
                echo '<div class="error_message box-red box">Attention! Please enter a valid trip duration.</div>';
                exit();
            }
              else if(trim($people) == '') {
                echo '<div class="error_message box-red box">Attention! Please enter a valid number of people.</div>';
                exit();
            }
             else if(!is_numeric($phone)) {
                echo '<div class="error_message box-red box">Attention! Phone number can only contain digits.</div>';
                exit();
            } else if(!isEmail($email)) {
                echo '<div class="error_message box-red box">Attention! You have enter an invalid e-mail address, try again.</div>';
                exit();
            }


            if(trim($comments) == '') {
                echo '<div class="error_message box-red box">Attention! Please enter your message.</div>';
                exit(); 
            }

            if(get_magic_quotes_gpc()) {
                $comments = stripslashes($comments);
            }


            // Configuration option.
            // Enter the email address that you want to emails to be sent to.
            // Example $address = "joe.doe@yourdomain.com";

            $address = "eric@ericbelldesigns.com";

            // Configuration option.
            // i.e. The standard subject will appear as, "You've been contacted by John Doe."

            // Example, $e_subject = '$name . ' has contacted you via Your Website.';

            $e_subject = 'Yacht Charter Booked by ' . $name . '.';


            // Configuration option.
            // You can change this if you feel that you need to.
            // Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

            $e_body = "You have been contacted by $name, their additional message is as follows." . PHP_EOL . PHP_EOL;
            $e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
            $e_reply = "You can contact $name via email, $email or via phone $phone";

            $msg = wordwrap( $e_body . $e_content . $e_reply, 70 );

            $headers = "From: $email" . PHP_EOL;
            $headers .= "Reply-To: $email" . PHP_EOL;
            $headers .= "MIME-Version: 1.0" . PHP_EOL;
            $headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
            $headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;

            if(mail($address, $e_subject, $msg, $headers)) {

                // Email has sent successfully, echo a success page.

                echo "<fieldset>";          
                echo "<div id='success_page' class='box-green box'>";
                echo "<p><b>Email Sent Successfully.</b></p>";
                echo "<p>Thank you $name, your message has been submitted to us.</p>";
                echo "</div>";
                echo "</fieldset>";
            } 
            else {
                echo 'ERROR!';
            }

为了让php访问发布的表单数据,输入需要有一个
名称
属性-

     <select id="people" name="people">
         <option value="" selected>Please Select</option>
         <option value="6">Up to 6</option>
         <option value="12">Up to 12</option>
     </select>
    ...
    <label for="email">E-mail address</label>
    <input type="email" id="email" name="email" />
    ...

请选择
最多6个
最多12个
...
电子邮件地址
...

由于
contact.php
上的表单在没有
name
属性的情况下工作,这表明表单是通过javascript提交的,javascript代码会用name属性发布值。

表单输入需要name属性-
。由于此表单在您的
contact.php
上工作时没有name属性,因此可能是使用javascript提交表单,并在其中添加name属性。啊!谢谢你,肖恩!!我没有想到这一点。我现在要检查脚本。就是这样。。我现在正在写剧本。如果你想补充这一点作为回答,我很乐意接受。我真的很感谢你的时间和帮助。嘿,肖恩,我在我的页面和这篇文章中添加了我认为正确的javascript(见最新编辑)。但是,我仍然收到无效的电子邮件地址错误。
        $('#bookingform').submit(function(){
            var action = $(this).attr('action');
            $("#message").show(500,function() {
            $('#message').hide();
            $('#submit')
                .after('<img src="images/contact-ajax-loader.gif" class="loader" />')
                .attr('disabled','disabled');

            $.post(action, { 
                name: $('#name').val(),
                email: $('#email').val(),
                phone: $('#phone').val(),
                address: $('#address').val(),
                city: $('#city').val(),
                state: $('#state').val(),
                zip: $('#zip').val(),
                date: $('#date').val(),
                duration: $('#duration').val(),
                people: $('#people').val()
            },
            function(data){
                document.getElementById('message').innerHTML = data;
                $('#message').slideDown('slow');
                $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
                $('#submit').removeAttr('disabled'); 
            });

            });
            return false; 
        });

        // CONTACT FORM
        $('#contactform').submit(function(){
            var action = $(this).attr('action');
            $("#message").show(500,function() {
            $('#message').hide();
            $('#submit')
                .after('<img src="images/contact-ajax-loader.gif" class="loader" />')
                .attr('disabled','disabled');

            $.post(action, { 
                name: $('#name').val(),
                email: $('#email').val(),
                phone: $('#phone').val(),
                comments: $('#comments').val()
            },
            function(data){
                document.getElementById('message').innerHTML = data;
                $('#message').slideDown('slow');
                $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
                $('#submit').removeAttr('disabled'); 
            });

            });
            return false; 
        });
     <select id="people" name="people">
         <option value="" selected>Please Select</option>
         <option value="6">Up to 6</option>
         <option value="12">Up to 12</option>
     </select>
    ...
    <label for="email">E-mail address</label>
    <input type="email" id="email" name="email" />
    ...