douwen4178 2018-04-26 05:39
浏览 91
已采纳

jQuery远程验证阻止提交按钮发布值

In my form, there is 2 submit button (save & exit, next) & remotely checking email address duplication. it's working fine. when submitting a form I'm not getting which submit button is clicked.

form.php

<form method="post" action="" id="user_reg_form" name="user_reg_form">
    <input class="form-control" id="user_id" value="<?php echo ($user->user_id!='')? $user->user_id:'0'; ?>" type="hidden" name="user_id">
    <div class="no-padding">
        <div class="col-md-12">
            <div class="form-group no-margin">
                <label>Email:</label>
                <input type="text" class="form-control" name="email" id="email" value="<?php echo ($user->email!='')? $user->email:''; ?>" maxlength="50">
            </div>
        </div>
    <div class="col-md-6">
        <div class="form-group no-margin">
            <label> Name</label>
            <input type="text" class="form-control" name="name" id="name" value="<?php echo ($user->name!='')? $user->name:''; ?>" maxlength="50">
        </div>
    </div>
    <div class="footer-btn" style="text-align:left;">
        <input type="submit" name="save_exit" id="save_exit" class="btn btn-primary"  value="Save & Exit"/>
        <input type="submit" name="next" id="next"  class="btn btn-success"  value="Next"/> 
        <a href="<?=base_url('home/user')?>" class="btn btn-default">Cancel</a> 
    </div>
</form>

jquery validation code:

$("#reg_form").validate({
    rules: {
        email:{
            required:true,
            remote: 
            {
                url: "<?php echo base_url('home/check_email_duplication')?>",   
                type: "post",
                data: { 'user_id': function() { return $("#user_id").val()},'email': function() { return $("#email").val()}},           
            },
        },
        name: "required",
    },
});

After form submit print $_POST array:

User Controller Action:

public function user_reg()
{
    print_r($_POST);
}

Button 1 Click:

Array ( 
    [user_id] => 14 
    [email] => test@test.com
    [name] => yyyy 
)

Button 2 Click:

Array ( 
    [user_id] => 14 
    [email] => test@test.com
    [name] => yyyy 
)

But I Need below-expected Response in the $_POST array: Need submit button value to find out which submit button.

Button 1 Click:

Array ( 
    [user_id] => 14 
    [email] => test@test.com
    [name] => yyyy 
    [next] => Next 
)

Button 2 Click:

Array ( 
    [user_id] => 14 
    [email] => test@test.com
    [name] => yyyy 
    [save_exit] => Save & Exit 
)

展开全部

  • 写回答

2条回答 默认 最新

  • doukesou4452 2018-05-07 05:10
    关注

    Finally, I found the answer which is worked for me.

    There is a change in jquery code. I've added 2 changes ignore: [] & async: false in remote condition this solved my issue.

    jquery form validation code:

    $("#reg_form").validate({
        ignore: [],
        rules: {
            email:{
                required:true,
                remote: 
                {
                    url: "<?php echo base_url('home/check_email_duplication')?>",   
                    type: "post",
                    data: { 'user_id': function() { return $("#user_id").val()},'email': function() { return $("#email").val()}}, 
                    async: false,         
                },
            },
            name: "required",
        },
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 cmake+mingw使用<mysqlx/xdevapi.h>报错
  • ¥15 eNSP中防火墙的使用
  • ¥15 不能对数据库增删改但是可以查询
  • ¥15 在触控设备上启动TabTip.exe打不开键盘界面,怎么用代码启动进程打开界面
  • ¥15 关于#mlnet#的问题:mlnet相关请求(语言-c#)
  • ¥15 lvgl7.11怎么做出文字被选中的效果
  • ¥50 如何快速查看手机目标app的主要服务器ip
  • ¥15 (标签-stm32|关键词-m3)
  • ¥15 matlab中频率调制法代码的解读
  • ¥15 ceph的对象、块、文件相关问题求解答
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部