javascript - 如何提交
问题描述
在提交表单时使用甜蜜警报时遇到麻烦,我通常使用 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;
})
});
如果您知道答案,请帮助我,谢谢
解决方案
我希望您正在尝试从用户那里获得确认,并且一旦确认您打算提交表单。为此,您需要对代码进行少量更改,如下所示,
一个。将 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();
})
希望能帮助到你。
推荐阅读
- json - 如何在 Go 中解码 JSON,它将多个元素作为类型数组返回,将单个元素作为类型返回
- tensorflow - tensorflow 1.x 重塑占位符
- networking - 如何将 VM 连接到 ad-hoc 网络?
- reactjs - 如何根据 React 中选择的选项显示组件?
- c# - “foreach”不过滤特定控件
- javascript - 当您在参数中只发送一个密钥时,您是否会发出“post”类型的请求?(最佳实践)
- python - 如何制作 Keras 神经网络输出值?
- kotlin - 将 RXJava Single 转换为协程的 Deferred?
- reactjs - 在反应js中更新没有回调函数的父组件
- python - range(start, stop, step) 但 start, stop, step 作为变量