如何使用甜蜜警报提交<form action =“”>。因为它必须使用“动作”。我通常使用href

时间:2019-04-12 18:46:05

标签: javascript sweetalert

我在提交表单时使用甜蜜警报时遇到麻烦,我通常使用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;
            })
        });

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

1 个答案:

答案 0 :(得分:0)

希望您尝试从用户那里获得确认,一旦确认,您打算提交表格。为此,您需要对代码进行一些改动,如下所示,

a。将ID添加到您的表单控件中,如下所示,

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

b。检查用户是否在甜蜜警报的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();
        })

希望有帮助。