dspym82000 2017-12-14 09:07 采纳率: 100%
浏览 29

当使用jQuery验证插件时,提交表单会导致空白页面

I'm using jQuery validate plugin in my form. Validation works fine except when I'm using this 'data' function to send data. When I comment out this data section, form is submitted and redirected properly and other validation is implemented properly. But using data , form is submitted and redirected to blank page.

Validation for checking duplicate email in database is checked here.. With the following data function, validation is working but the submission is not working.

Here's my part of validation script:

personal_email: {
    email: true,
    remote: {
       param:{
           url: app.baseurl('user/check_personal_email'),
           type: 'POST',
           data: 
             {
               userID : function()
                     {
                      return $("#userID").val();
                     }
             }

            }
            // ,
            //  depends: function(element)
            //  {
            //      return ($('#editTrue').val() == undefined && $('#editTrue').val() == null);
            //  }
              }
            },

Controller function that handles and returns the above url request is :

public function checkPersonalEmailExists($f3)
{
    $userID = $f3->get('POST.userID');
    $email = $f3->get('POST.personal_email');
    $user = new UserModel();
    $records = $user->checkIfPersonalEmailExists($email);

    if(count($records) > 0)
    {
        foreach ($records as $record) 
        {
            $user_id = $record['id'];
        }
        echo ($userID == $user_id) ? 'true' : 'false';
    }
    else
    {
        echo 'true';
    }
}

Here's my HTML form:

<form method="post" action="user/save" id="employee-form">
    <input name="personal_email" type="email" class="form-control" id="personal_email">
    <button type="submit" class="btn btn-primary" name="update" value="update">Update User</button>
</form>

Form submission is handled by following function:

public function save($f3)
{
   $save = $f3->get('POST.save');
   $update = $f3->get('POST.update');

   if(isset($save) || isset($update))
     {
        echo 'It is working';
        // saving to database stuff...
        exit;
     }
   else
     {
        echo 'It is not working';
        exit;
     }
}

One thing I noticed is that when every elements are filled with valid data.. then only it is acting this way. Else, it is displaying 'It is working'.

It seems that with data in validation, submit button value is not recognized.. It displays 'It is not working'.

I cannot figure out what's wrong, and how jQuery validation plugin behaves.

Please help me with this. Any help is very much appreciated. Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 AT89C51控制8位八段数码管显示时钟。
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题