0

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.

This is my js code:

 $('#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

4

2 回答 2

1

You need the php form in the action section of the form whose script will run once a form is validated.

Sample contact form html code

<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

<?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

于 2013-10-26T10:56:01.943 回答
-2
< form action="email.php" >

In the form action page you can get the values there you can send the email

于 2013-10-26T10:56:42.910 回答