[英]Submitting a php pop-up form with javascript
I have a pop up form in php that is opened by javascript. 我有一个用javascript打开的php弹出表单。 I want this to be sent to my database when I click on submit.
我希望在单击“提交”时将其发送到我的数据库。 The php form works fine without the javascript, but when added it doesn t work.
php表单在没有javascript的情况下可以正常工作,但是添加后无法正常工作。 Would you have any idea how to solve this.
您有任何解决方法的想法吗?
</style>
<script type='text/javascript'>
$(document).ready(function() {
$('#box_form').dialog({
autoOpen: false,
height: 375,
width: 350,
modal: true,
buttons: [
{
text: "Cancel",
click: function() {
$(this).dialog("close");
}},
{
text: "Submit",
click: function() {
$('#former').submit();
}}
]
});
$('#clicky').button().click(function(e){
$('#box_form').dialog('open');
});
});
</script>
</head>
<body>
<form id="former" method="post" action="film_post.php" name="former">
<div id="box_form">
<select id="option" name="option">
<option value="film">film</option>
<option value="livre">livre</option>
<option value="musique">musique</option>
</select></p>
<p>
<select id="star" name="star">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select></p>
<label for="nom">nom</label> : <input type="text" name="nom" id="nom" /><br />
</div>
</form>
<input type="button" id="clicky" value="Show Form">
and the film_post.php file is: film_post.php文件为:
try
{
$bdd = new PDO('mysql:host=localhost;dbname=website', 'root', 'root');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$option = $_POST['option'];
$star = $_POST['star'];
if ($option == film AND $star = 1) {
$req = $bdd->prepare('INSERT INTO film (film, star) VALUES(?,?)');
$req->execute(array($_POST['nom'],$_POST['star'] )); }
elseif ($option == film AND $star = 2) {
$req = $bdd->prepare('INSERT INTO film (film, star) VALUES(?,?)');
$req->execute(array($_POST['nom'],$_POST['star'] )); }
elseif ($option == film AND $star = 3) {
req = $bdd->prepare('INSERT INTO film (film, star) VALUES(?,?)');
$req->execute(array($_POST['nom'],$_POST['star'] )); }
Apparently I can't post images yet, so here's a link to the one I have talk about in my answer below. 显然我还不能发布图片,因此,这是我在下面的回答中所讨论的图片的链接。 http://i.stack.imgur.com/xgExo.png
http://i.stack.imgur.com/xgExo.png
I executed your code, grabbing the necessary script src tags, which I assume you have in your actual code, and found the same problem you did. 我执行了您的代码,抓住了必要的脚本src标记(假定您已在实际代码中使用了该标记),并发现了同样的问题。 After looking at the firebug console, like jchapa suggested, I found what you can see in the images above.
在查看了Firebug控制台(如jchapa建议的那样)之后,我发现您可以在上面的图像中看到什么。
The jquery ui you are using rewrites your from in such a way that not only does it give it those bubbly graphics but it also terminates your form tag prematurely, as seen where I have underlined the "" text. 您正在使用的jQuery用户界面以这样的方式重写您的jQuery UI:它不仅为其提供了那些起泡的图形,而且还过早地终止了表单标签,正如我在下划线“”处所看到的那样。
How you fix this, I don't know, but that is where your problem lies. 我不知道如何解决此问题,但这就是问题所在。 You might consider looking online for how to setup a form in this jquery ui or you might just build your own from dialog.
您可以考虑在线查找如何在此jQuery UI中设置表单,也可以只通过对话框构建自己的表单。 Admittedly, though, the graphics won't be quite as sleek.
诚然,图形不会那么时尚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.