[英]success message with popup after submit
I have a form that allows you to enter the new songs in the database. 我有一个表格,可以让您在数据库中输入新歌曲。 The problem is when I click on the button "save" I would like to bring up a popup with the message of successful inclusion.
问题是,当我单击“保存”按钮时,我想弹出一个包含成功包含消息的弹出窗口。 I have two files, one representing the view, and the other controller.
我有两个文件,一个代表视图,另一个代表控制器。 Can I put a variable in the controller that contains the JavaScript code that allows me to bring up the popup and then retrieve it from view?
我可以在包含JavaScript代码的控制器中放入一个变量,该变量允许我调出弹出窗口,然后从视图中检索它吗?
This is the controller ( i use Slim Framework). 这是控制器(我使用Slim Framework)。
$popup = array();
$popup = '$(function(){
$( "#dialog-message" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
});';
$app->render('newkaraoke.html', array('pop'=>$popup));
this is the view where the reference variable 这是参考变量所在的视图
<?php echo $pop;?>
My solution does not take any framework into account, but should work regardless. 我的解决方案没有考虑任何框架,但是无论如何都可以工作。
The easiest method you could make for this is a simple if()
statement like so: 您可以使用的最简单的方法是一个简单的
if()
语句,如下所示:
if(isset(_POST['submit-music'])) {
echo "
<div id='success-message'>Your song has been added to the database</div>
";
}
This code works as long as you pass the $_POST['submit-music']
variable to the view. 只要将
$_POST['submit-music']
变量传递给视图,此代码就起作用。 You could always put the POST var in something easier like $submitted
and just check if that exists. 您总是可以将POST var放在诸如
$submitted
类的更简单的名称中,然后检查是否存在。
For removing the pop-up (if you want to) I wrote the following code (it uses JQuery however, but you might be able to create a Javascript alternative). 为了删除弹出窗口(如果需要),我编写了以下代码(尽管它使用JQuery,但是您可能可以创建Javascript替代方法)。
$('document').ready(function() {
$('#success-message').delay(3000).fadeOut();
});
3000 is the amount of time that passes before fading the div out. 3000是淡出div之前经过的时间。 In this case it's set to 3 seconds.
在这种情况下,它设置为3秒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.