【问题标题】:How do I use sweetalert2 with php form in CodeIgniter?如何在 CodeIgniter 中使用 sweetalert2 和 php 表单?
【发布时间】:2018-07-21 02:01:49
【问题描述】:

详细信息:如何在 CodeIgniter 中将 sweetalert2 与 PHP 表单一起使用? 实际上,我想在提交 PHP 表单时显示 sweetalert2,然后显示 sweetalert2 以确认数据,如果用户确认应提交数据,然后重定向到下一页。

问题:但在我的情况下,它直接重定向到下一页,而我没有按 sweetalert 上的确认按钮。

PHP:

echo form_open( '/redirect to',['onsubmit'=>'return submitForm(this);']);

JavaScript:

function submitForm(){

    swal({ 

    title: "Are you Sure!",

     text: "Data is Correct?",

           type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#cc3f44",
            confirmButtonText: "Yes!",
            closeOnConfirm: false
        }).then(okay =>  {
            if(okay)
            {
              alert("check");
            }
            else
            { 
              alert("not sure");
            }
        });

}

PHP

echo form_submit(['name'=>'submit','id'=>'submit','value'=>'Submit', 'class'=>'btn btn-primary btn_size' ]); 

请帮助我解决这个问题。提前致谢。

【问题讨论】:

  • 现在显示什么
  • 它只是在没有我确认的情况下重定向到下一页

标签: javascript php forms codeigniter sweetalert2


【解决方案1】:

我在这里发布我的工作代码。我通过甜蜜警报删除了事件它通过为按钮提供类名“demo”映射到按钮希望它会有所帮助

$('.demo').click(function () {
    //e.preventDefault();
    var id= document.getElementById('id').value;
    swal({
            title: "Are you sure?",
            text: "Your will not be able to recover this Event!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes, delete it!",
            cancelButtonText: "No, cancel plz!",
            closeOnConfirm: false,
            closeOnCancel: false },
        function (isConfirm) {
            if (isConfirm) {
                    location.href='<?php echo site_url('calendarController/delete_Event/'); ?>'+'/'+id;

            } else {
                swal("Cancelled", "Your event is safe :)", "error");
            }
        });
});

【讨论】:

  • 如果您仍然感到任何复杂性,您可以问!
  • 还要确保以正确的方式包含您的库
  • 那是我包含在我的 js 中的库
  • 发布您的模型并在此处查看让我们看看我们能做什么
猜你喜欢
  • 1970-01-01
  • 2022-01-06
  • 2021-10-28
  • 2016-12-05
  • 1970-01-01
  • 1970-01-01
  • 2021-06-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多