简体   繁体   English

提交表单jquery验证插件

[英]submitting form jquery validation plugin

I'm using jquery validation plugin to validate contact form in my web but I don't know how to pass form fields after validation to a php file to send it to my peronal email. 我正在使用jquery验证插件来验证我的Web中的联系表单,但我不知道如何将验证后的表单字段传递到php文件,以将其发送到我的永久电子邮件。

This is my js code: 这是我的js代码:

 $('#contact-us').validate(
 {
  rules: {
    contactName: {
      minlength: 2,
      required: true
    },
    email: {
      required: true,
      email: true
    },
    subject: {
      minlength: 2,
      required: true
    },
    comments: {
      minlength: 2,
      required: true
    }
  },
  highlight: function(element) {
            $(element).closest('.form-group').addClass('has-error');
        },
        unhighlight: function(element) {
            $(element).closest('.form-group').removeClass('has-error');
        },
        errorElement: 'span',
        errorClass: 'help-block',
        errorPlacement: function(error, element) {
            if(element.parent('.input-group').length) {
                error.insertAfter(element.parent());
            } else {
                error.insertAfter(element);
            }
        }

    });
}); // end document.ready

I think I have to use something like that solution but I can't get it work. 我认为我必须使用类似的解决方案,但无法使其正常工作。

Anybody could help me? 有人可以帮助我吗? Thanks in advance 提前致谢

You need the php form in the action section of the form whose script will run once a form is validated. 您需要在表单的操作部分中的php表单,该脚本的脚本将在表单被验证后运行。

Sample contact form html code 样本联系表html代码

<form method="post" action="submit.php" id="formwa">
<label  for="name">Your Name</label>
<input type="text" name="name" id="name" placeholder="Your name here">
<label  for="email">Email address</label>
<input type="email" name="email" id="email" placeholder="Enter email">
<button type="submit" class="btn btn-warning">Keep me Updated!</button>
</form>

Correspondin submit.php code 对应的Submit.php代码

<?php
  //$to = $_POST['to'] ;    
  $message = "Hi there, \n You have a new visitor on your Website.\n\r The person's name is: ".$_POST['name']."\r\n\r\nAnd the person's Email id is: ".$_POST['email'];
  $from = $_POST['email'];
  $headers =  "From: ".$_POST['email'];
  mail( "you@yourdomain.com", "Subject Line for the Email", $message, $headers);
  // mail( "another@yourdomain.com", "Carbon Copy: Subject Line", $message, $headers);

?> 

I hope that'll help you to understand it. 希望对您有所帮助。 The above codes lack validation, but alright, you have been working on validation itself. 上面的代码没有验证,但是好的,您一直在进行验证本身。 Ask more in case of more confusion. 如有更多困惑,请问更多。 Cheers 干杯

< form action="email.php" >

在表单操作页面中,您可以获得在那里可以发送电子邮件的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM