Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 电子邮件表单验证_Php_Jquery - Fatal编程技术网

Php 电子邮件表单验证

Php 电子邮件表单验证,php,jquery,Php,Jquery,我在验证电子邮件表单时遇到问题。最初,我使用PHP在填写并提交表单后发送电子邮件,使用: <?php if(isset($_POST['submit'])){ $to = "me@gmail.com"; // this is your Email address $from = $_POST['email']; // this is the sender's Email address $first_name = $_POST['customer_name']; $last_name =

我在验证电子邮件表单时遇到问题。最初,我使用PHP在填写并提交表单后发送电子邮件,使用:

<?php
if(isset($_POST['submit'])){
$to = "me@gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['customer_name'];
$last_name = $_POST['company_name'];
$vat_number = $_POST['vat_number'];
$business_type = $_POST['business_type'];
$subject = "Customer Sign Up";
$message = $first_name . " from " . $last_name . " has applied to be a customer." . "\n\n" . "About their business:" . " " . $_POST['message'] . "\n\n" . "VAT Number: " . $vat_number . "\n\n" . "Business type: " . $_POST['business_type'];

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);

}
?>

表单中再也没有名为“提交”的输入字段了。。。复制粘贴提交按钮时可能会脱落;)

我认为您在复制和粘贴时可能忘记设置表单
操作
字段:)如果没有,请让我们知道完整的代码。

不要试图从您的工作中拿走任何东西,但是

这会让你的生活更轻松

例如:

**HTML**

<form id="myform" action="my-action" method="post" class="reg-form">
      <h2>Sign up form</h2>
      <table class="form">
        <tr>
          <td><label for="customer_name">Your Name: </label></td>
          <td><input type="text" name="customer_name" class="text-input" id="test"></td>
        </tr>
        <tr>
          <td><label for="company_name">Company Name: </label></td>
          <td><input type="text" name="company_name" class="text-input"></td>
        </tr>
        <tr>
          <td><label for="vat_number">VAT Number/Tax Code: </label></td>
          <td><input type="text" name="vat_number" class="text-input"></td>
        </tr>
        <tr>
          <td><label for="email">Email: </label></td>
          <td><input type="text" name="email" class="text-input"></td>
        </tr>
        <tr>
          <td><label for="business_type">Physical or online business? </label></td>
          <td><select name="business_type"><option>Physical Store</option><option>Online Store</option><option>Physical &amp; Online store</option></select></td>
        </tr>
        <tr>
          <td><label for="message">Tell us more about your business: </label></td>
          <td><textarea rows="5" name="message" cols="50" class="textarea-input"></textarea></td>
        </tr>
        <tr>
          <td></td>
          <td><input type="submit" value="Submit" class="button green-btn" id="sign-submit" /></td>
        </tr>
      </table>
      </form>
在jquery库调用之后,您只需要包括验证器库:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>


@FoX该标记中的name属性在哪里?@FoX是一个简单的代码段。。。意思很清楚。。。它做了一些验证…它对我有效:。在名称字段中输入
correct
时,表单将被提交。顺便说一下,对于客户端验证,您还可以将
required
属性添加到表单元素中,但这当然取决于要执行的验证类型。
var validator;

validator = $('#myform').validate({
'rules': {
    'email': {
        'required': ture,
        'email': true
    }
    'messages': {
        'email': {
            'required': "An email address is required",
                'email': "Please use a valid email address."
        }
    },
        'onkeyup': false,
        'submitHandler': function (form) {
        alert('Submit!');
        // form.submit();
    }
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>