有人可以用这个联系验证表格帮我吗?

时间:2013-08-15 06:41:48

标签: php javascript jquery html

好的,我需要将此联系表单突出显示为红色,并在框内说无效!我做什么我无法让它工作!我无法更改已添加到HTML中的HTML标记,但不能删除任何HTML标记,但我希望它与JavaScript显示在同一页面上,看起来非常好,有人可以编辑我所拥有的内容并提供帮助我请这个工作!

哦,我每次测试时都会收到2封电子邮件!

这里有HTML:

        <!-- Contact -->
        <div class="wrapper wrapper-style4">
            <article id="contact">
                <header>
                    <h2>Want to hire me? Get in touch!</h2>
                    <span>I do quality work and would love to work for you!.</span>
                </header>
                <div>
                    <div class="row">
                        <div class="12u">
                        <div id="errors"></div>
                            <form method='post' action='mailform.php' id='contact-form'>
                                <div>
                                    <div class="row half">
                                        <div class="6u">
                                            <input type="text" name="name" id="name" placeholder="Name" />
                                        </div>
                                        <div class="6u">
                                            <input type="text" name="email" id="email" placeholder="Email" />
                                        </div>
                                    </div>
                                    <div class="row half">
                                        <div class="12u">
                                            <input type="text" name="subject" id="subject" placeholder="Subject" />
                                        </div>
                                    </div>
                                    <div class="row half">
                                        <div class="12u">
                                            <textarea name="message" id="message" placeholder="Message"></textarea>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="12u">
                                            <a href="#" class="button form-button-submit">Send Message</a>
                                            <a href="#" class="button button-alt form-button-reset">Clear Form</a>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
        <!-- Contact -->
        <div class="wrapper wrapper-style4">
            <article id="contact">
                <header>
                    <h2>Want to hire me? Get in touch!</h2>
                    <span>I do quality work and would love to work for you!.</span>
                </header>
                <div>
                    <div class="row">
                        <div class="12u">
                        <div id="errors"></div>
                            <form method='post' action='mailform.php' id='contact-form'>
                                <div>
                                    <div class="row half">
                                        <div class="6u">
                                            <input type="text" name="name" id="name" placeholder="Name" />
                                        </div>
                                        <div class="6u">
                                            <input type="text" name="email" id="email" placeholder="Email" />
                                        </div>
                                    </div>
                                    <div class="row half">
                                        <div class="12u">
                                            <input type="text" name="subject" id="subject" placeholder="Subject" />
                                        </div>
                                    </div>
                                    <div class="row half">
                                        <div class="12u">
                                            <textarea name="message" id="message" placeholder="Message"></textarea>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="12u">
                                            <a href="#" class="button form-button-submit">Send Message</a>
                                            <a href="#" class="button button-alt form-button-reset">Clear Form</a>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

我需要这里的JavaScript:

    <script>

    </script>

PHP表单在这里:

    <?php
$to = "bcw1995@gmail.com";
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$from = $_REQUEST['email'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail($_REQUEST['email'], $subject,
  $message, "From:" . $email);
  }
  header("Location: http://www.thorbis.com/#contact");
?>

有人可以解决这个问题,你将成为一个救生员!

1 个答案:

答案 0 :(得分:0)

您收到两封电子邮件:

您的邮件发送两次,因为您正在调用mail()函数两次。删除此行mail($to,$subject,$message,$headers);

//编辑

将第二个电子邮件功能更改为:mail($to, $subject, $message, "From:" . $email); 否则发件人将收到他发送的电子邮件。

<强>验证

Javascript表单验证有很多方法和库。我推荐jQuery + jQuery.Validation插件(http://jqueryvalidation.org/)。 但我也会在PHP文件中添加一个验证,因为如果有人禁用了javascript,他可以发送空的电子邮件。

我希望我能帮助你。