V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
dongchen
V2EX  ›  PHP

请教一下关于在 PHP codeIgniter 中表单提交前使用 js 确认的问题。

  •  
  •   dongchen · 2020-02-09 18:51:01 +08:00 · 2392 次点击
    这是一个创建于 1538 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用的是 bootstrap 4 和 bootboxjs

    view

    <?php echo form_open('panel/webconfig_post',array('class'=>'pt-4'));?>
    ...
    ...
    <button class="btn btn-primary mr-5" type="submit" id='kk'>提交</button>    
    <button class="btn btn-danger ml-5" type="reset">重置</button>
    

    js

    <script>
    $(document).on("click", "#kk", function(e) {
        bootbox.confirm({
        message: "确定要提交吗?",
        locale: 'zh_CN',
        callback: function (result) {
            console.log(result);
            }
        });
    });
    </script>
    

    想问下怎么写 js 才能点击窗口的确定之后再提交呢?

    现在的情况是,点击提交,出现弹窗,但是不用点击直接提交表单到panel/webconfig_post这个控制器了

    不会 js 😂

    第 1 条附言  ·  2020-02-12 19:03:21 +08:00

    感谢@commoccoom,已经按照链接中的方法成功了

    <script type="text/javascript">
        // 表单提交前询问确认
        $('#webconfig_form').submit(function(e) {
            var currentForm = this;
            e.preventDefault();
            bootbox.confirm({            
                message: "确定要提交吗?",
                locale: 'zh_CN',        
                callback: function(result) {
                if (result) {
                    currentForm.submit();
                    }
                }
            });
        });
    </script>
    
    U2Fsd
        1
    U2Fsd  
       2020-02-09 20:24:04 +08:00
    LZ 不看文档的吗?

    ```
    bootbox.confirm({
    message: "This is a confirm with custom button text and color! Do you like it?",
    buttons: {
    confirm: {
    label: 'Yes',
    className: 'btn-success'
    },
    cancel: {
    label: 'No',
    className: 'btn-danger'
    }
    },
    callback: function (result) {
    console.log('This was logged in the callback: ' + result)
    }
    })

    ```
    U2Fsd
        2
    U2Fsd  
       2020-02-09 20:25:29 +08:00
    result 会返回 true 或者 false
    dongchen
        3
    dongchen  
    OP
       2020-02-09 20:30:50 +08:00
    @U2Fsd 返回 true 或者 false 之后怎么处理呢?对 js 不是很懂😭
    U2Fsd
        4
    U2Fsd  
       2020-02-10 00:15:33 +08:00
    @dongchen

    根据 true false 判断要不要提交表单
    dongchen
        5
    dongchen  
    OP
       2020-02-10 00:28:14 +08:00
    @U2Fsd .......不会写才问的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1026 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:21 · PVG 03:21 · LAX 12:21 · JFK 15:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.