使用甜蜜警报。因为它必须使用“动作”。我通常使用href,javascript,sweetalert"/>

首页 > 解决方案 > 如何提交

使用甜蜜警报。因为它必须使用“动作”。我通常使用href

问题描述

在提交表单时使用甜蜜警报时遇到麻烦,我通常使用 href 但它必须使用
我不知道的表单操作:(

<form class="form-horizontal text-right m-b-1" action="<?php echo base_url('pegawai/editfoto') ?>" method="POST">

                        <div class="col-9 ">
                            <div class="fileupload fileupload-new" data-provides="fileupload">
                                <div class="fileupload-new thumbnail " style="width: 200px; height: 150px;">
                                    <img src="<?php echo base_url('uploads/'.$data[0]->foto)?>" alt="image" class="img-fluid" />
                                </div>
                                <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
                                <div>
                                    <button type="button" class="btn btn-custom btn-file">
                                        <span class="fileupload-new"><i class="fa fa-paper-clip"></i> Select image</span>
                                        <span class="fileupload-exists"><i class="fa fa-undo"></i> Change</span>
                                        <input type="file" name="foto" class="btn-light" />
                                    </button>
                                    <a href="#" class="btn btn-danger fileupload-exists" data-dismiss="fileupload"><i class="fa fa-trash"></i> Remove</a>
                                </div>
                            </div>
                          </div>
                          <br>
                          <div class="form-group account-btn text-center m-t-10">
                              <div class="col-12">
                                  <button type="button" class="btn w-lg btn-rounded btn-primary waves-effect waves-light" id="sa-editfoto" >Save</button>
                              </div>
                          </div>
                      </form>

和甜蜜警报的代码

$('#sa-editfoto').click(function () {
          var link= $(this).attr("link-href")
          $('#sa-editfoto').attr("src", link);
            swal({
                title: 'Apakah Anda Yakin?',
                text: "Foto Profile akan diubah",
                type: 'question',
                showCancelButton: true,
                confirmButtonClass: 'btn btn-confirm mt-2',
                cancelButtonClass: 'btn btn-cancel ml-2 mt-2',
                confirmButtonText: 'Yes'
            }).then(function () {
              window.location.href = link;
            })
        });

如果您知道答案,请帮助我,谢谢

标签: javascriptsweetalert

解决方案


我希望您正在尝试从用户那里获得确认,并且一旦确认您打算提交表单。为此,您需要对代码进行少量更改,如下所示,

一个。将 id 添加到您的表单控件,如下所示,

<form id="form1" class="form-horizontal text-right m-b-1" action="<?php echo base_url('pegawai/editfoto') ?>" method="POST">

湾。检查用户是否在 sweet alert 的 javascript 上确认提交,如下所示,

       swal({
            title: 'Apakah Anda Yakin?',
            text: "Foto Profile akan diubah",
            type: 'question',
            showCancelButton: true,
            confirmButtonClass: 'btn btn-confirm mt-2',
            cancelButtonClass: 'btn btn-cancel ml-2 mt-2',
            confirmButtonText: 'Yes'
        }).then(function (isConfirmed) {
           // If user confirmed submit the form
           if(isConfirmed)
              $("#form1").submit();
        })

希望能帮助到你。


推荐阅读