Example explanation of php submitting form and closing layer pop up window iframe
- 2021-10-27 06:43:27
- OfStack
Introduce a very easy-to-use front-end pop-up plug-in:
layer official website address: http://layer.layui.com/
According to the official API: iframe pop-up window of layer
//iframe Layer - Parent-child operation
layer.open({
type: 2,
area: ['700px', '530px'],
fix: false, // Unfixed
maxmin: true,
content: 'test/iframe.html'
});
Here, take php development as an example to demonstrate how to automatically close the layer pop-up window after submitting a form
(1) layer edit box pops up:
function edit(id){
if(id==null||id==''||id=='undefined'){
alert(' Operation number is blank, please contact the administrator ');
}
layer.open({
type: 2,
area: ['700px', '530px'],
fix: false, // Unfixed
maxmin: true,
content: 'index.php?m=content&c=meiti&a=edit_paiqi&id='+id
});
}
(2) Edit the main code of the page
<input name="dosubmit" type="submit" id="dosubmit" value=" Submit " class="button" >
(3) Save data in the background of php and point to a method to close layer window
public function edit_config_paiqi(){
$id = trim($_REQUEST['id']);
$paiqi_db = pc_base::load_model('paiqi_config_model');
if($_REQUEST['dosubmit']){
$insertinfo = array();
$insertinfo['catid'] = trim($_POST['catid']);
$insertinfo['meitiid'] = trim($_POST['meitiid']);
$insertinfo['title'] = trim($_POST['title']);
$insertinfo['meitizhuname'] = trim($_POST['meitizhuname']);
$insertinfo['meitizhuid'] = trim($_POST['meitizhuid']);
$insertinfo['createtime'] = SYS_TIME;
$insertinfo['saturation'] = trim($_POST['saturation']);
$datas = $paiqi_db->update($insertinfo,array("id"=>$id));
if($datas){
<span style="color:#ff0000;">showmessage(L('operation_success'),'?m=content&c=meiti&a=closewindow');// Save successfully to close window method </span>
}
}else{
$datas = $paiqi_db->select(array("id"=>$id));
$template = "edit_config_paiqi";
include $this->admin_tpl($template);
}
}
/**
* Shut down layer Layer
*/
public function closewindow(){
$template = "close_layer";
include $this->admin_tpl($template);
}
(4) Close the window and refresh the key code of the parent window page
$(function(){
parent.location.reload();// Refresh parent window
parent.layer.closeAll();// Close all layer Window
});
Note: This page needs to load the js library required by layer to use the layer method