2015-02-24 54 views
0

我在这里有一个演示:http://hane-content.com/datepick/如何在php验证脚本中捕获jquery datepicker输入?

我有两个字段,名称和日期。 Jquery Datepicker附加到日期字段。我可以填写姓名字段,选择一个随机日期,然后点击提交。但是,当表单数据通过email.php处理时,会返回一个错误,说明日期尚未填写,例如日期字段为空。我是初学者。

你如何解决这个问题?
email.php

<?php 
// email.php 

$errors   = array();  // array to hold validation errors 
$data   = array();  // array to pass back data 

if (empty($_POST['datoa'])) 
    $errors['dateoa'] = 'Date is required.'; 

if (empty($_POST['name'])) 
    $errors['name'] = 'Name is required.'; 

// return a response =========================================================== 

// if there are any errors in our errors array, return a success boolean of false 
if (! empty($errors)) { 

    // if there are items in our errors array, return those errors 
    $data['success'] = false; 
    $data['errors'] = $errors; 
} else { 

    // if there are no errors process our form, then return a message 

    // DO ALL YOUR FORM PROCESSING HERE 
    // THIS CAN BE WHATEVER YOU WANT TO DO (LOGIN, SAVE, UPDATE, WHATEVER) 

    // show a message of success and provide a true success variable 
    $data['success'] = true; 
    $data['message'] = 'Success!'; 
} 

// return all our data to an AJAX call 
echo json_encode($data); 
?> 
+1

**错字** - '我会让你找到它 – 2015-02-24 20:07:56

回答

0

你如果拼写错误dateoa ...您的代码

(empty($_POST['datoa'])) 

应该是:

(empty($_POST['dateoa'])) 

(或更改输入名称在HTML表单中)。

+1

大声笑!对于在这方面浪费你的时间,对所有评论过的人表示歉意。 – hnewbie 2015-02-24 20:19:44

0

是啊,作为大衮说,错字。

if (empty($_POST['datoa'])) 

应该

if (empty($_POST['dateoa']))