When the form form submits the data and deletes the article, the default information hint page of TP does not look very good, so how do you want to implement the pop-up window hint?
Front end: A knowledge of the front end can be used the--iframe,iframe element creates an inline frame with another document, target, which specifies where to open the linked document.
In addition, want to achieve a good-looking convenient, can re-use the pop-up window will be developed a pop-up window plug-in, which is recommended to use the front-end pop-up window plug-in sweetalert.js, in order to facilitate, re-use we put it into a function, the page to introduce sweetalert.js CSS and JS file
Backend: In order to facilitate later reuse, write a public function, is called before the front-end encapsulation function pop-up prompt message
First, the form submission data, the front-end HTML code, to the IFRAME hidden, otherwise it will show the IFRAME in the page; the target in the form indicates that the form form is opened in the IFRAME
<iframestyle= "Display:none"name= "If"></iframe> <formAction= "{: URL (' Login/index ')}"Method= "POST"Target= "If"> <Divclass= "Panel Loginbox"> <Divclass= "Panel-body"> <Divclass= "Form-group"> <Divclass= "Field Field-icon-right"> <inputtype= "text"name= "username"ID= "username"placeholder= "Login Account"Required Value= "Admin" /> <spanclass= "icon icon-user margin-small"></span> </Div> </Div> <Divclass= "Form-group"> <Divclass= "Field Field-icon-right"> <inputtype= "Password"class= "Input Input-big"name= "Password"ID= "Password"placeholder= "Login Password"Required/> <spanclass= "icon Icon-key margin-small"></span> </Div> </Div> </Div> <Divstyle= "padding:30px;"> <inputtype= "Submit"ID= "button"class= "button Button-block bg-main text-big input-big"value= "Login"> </Div> </Div> </form>
Functions for front-end encapsulation
1 /**2 * Prompt pop -up window3 * @param text pop-up window content4 * @param type icon, default NULL, can fill success, error, warning, info, question5 * @param bool Showcancelbutton Whether the Cancel button is displayed6 * @param callback the function executed after pressing the confirmation key7 * @param all_callback Press the button, the pop-up window disappears when the function is executed8 */9 Ten functionMy_alert (text,type,callback,showcancelbutton,all_callback) { One varNow_text = text? Text: ' Are you sure? '; A varNow_type = type? Type:NULL; - varNow_showcancelbutton = Showcancelbutton? Showcancelbutton:false; - varNow_callback = callback? Callback:function () {}; the varAll_callback = All_callback? All_callback:function(Dismiss) {}; - - if(typeof(arguments[1]) = = "function") { -Now_type =NULL; +Now_callback = arguments[1]; -Now_showcancelbutton = arguments[2]; + } A at Swal ({ - Text:now_text, - Type:now_type, - Showcancelbutton:now_showcancelbutton, -Confirmbuttontext: ' OK ', -Cancelbuttontext: ' Cancel ', in -}). Then (function () { to Now_callback (); + },all_callback) -}
Back-end encapsulation public functions
1 /**2 * The IFRAME window calls the parent window: Parent.functionname ();3 * @param $data Pop-up window information4 * @param string $type pop-up box type5 * @param bool $is _reload is refreshed6 * @param string $url new page open address7 * @param8 */9 functionPhp_alert ($data,$type= ' ERROR ',$is _reload=false,$url= ' '){Ten if(Empty($url) &&!$is _reload){ One Echo"<script>parent.my_alert ('$data‘,‘$type') </script> "; A die; -}Else if(Empty($url) &&$is _reload){ - Echo"<script>parent.my_alert ('$data‘,‘$type', function () {parent.location.reload ();}) </script> "; the}Else{ - Echo"<script>parent.my_alert ('$data‘,‘$type', function () {parent.location.href = '$url‘;}) </script> "; - die; - } +}
Use, callback address to write module/controller/method, if not write module admin will put controller article as module, reported article module does not exist
1 if ($save) {2 // $this->success (' Add article Success ', ' Index '); 3 Php_alert (' Add article success! ', ' success ',false, '/admin/article/index '); 4 }else{5 php_alert (' Add article failed! ', ' Error ',false); 6 // $this->error (' Add article failed ', ' index '); 7 }
Eject Validate verification information
1 $validate = \think\loader::validate (' article '); 2 if ($validate->scene (' Update ')->check ($data)) {34 } Else {5 $msg $validate-GetError (); 6 Php_alert ($msg, ' Error ',false); 7 }
Second, delete articles, administrators
Back-end encapsulation function, because the page will jump when the data is deleted, the page does not have the Sweetalert plug-in related files, so to output the introduction of related files
1 /**2 * Custom TP comes with the jump prompt page;3 * @param data Pop-up window information4 * @param string $type pop-up box type5 * @param string Callable new page open address6 */7 functionAlert_msg ($text= ",$type= ' ERROR ',$callback= ' '){8 Echo' <meta charset= ' utf-8 "/><link href="/public/static/common/css/sweetalert.min.css "rel=" stylesheet "> <script src= "/public/static/admin/js/jquery_002.js" ></script><script type= "Text/javascript" src= "/ Public/static/common/js/sweetalert.min.js "></script> <script src="/public/static/admin/js/my_ Config.js "></script>";9 Echo"<script>window.onload=function () {My_alert ('$text‘,‘$type', function () {location.href = '$callback‘;})} </script> ";Ten die; One}
Call
1 Public functiondel () {2 $del= db (' admin ')->where (' id ', input (' id '))Delete ();3 if($del){4Alert_msg (' Delete admin succeeded! ', ' success ', '/admin/admin/index ');5}Else{6Alert_msg (' Delete admin failed! ', ' Error ', '/admin/admin/index ');7 }8}
thinkPHP5.0 use form form to submit data and delete articles without the tip page of TP, use pop-up hint message