【发布时间】:2011-05-10 05:57:09
【问题描述】:
目标:允许用户点击页面上的按钮/链接(称为主机页面),出现一个包含表单的模式。用户填写表单并点击提交按钮,数据写入mysql。模式关闭,用户只能查看“主机页面”。
我有这 2/3 的工作。单击创建与表单一起加载的模式。添加到表单的数据被写入数据库。模式在提交后关闭。 问题出现在流程的最后。当用户提交时,模式关闭,用户看到的是“表单”页面,而不是“主机”页面。此外,表单似乎将表单 datab 两次插入数据库。
问题 我想做的事情是否可行,如果可以,我将如何改变流程?
代码(host.php)
主机页面
<div>
<h2>Test Section</h2>
<p> This <a id="target" href="http://localhost/dialogExperiments/TESTsingleformfeedback.php" title="Test Form">LINK</a> opens the feedback form.</p>
</div>
表单页面(form.php)
<body>
<!-- Begin forms section --><div>
<h1> Form</h1>
<!-- First section is php script to process this particular form-->
<?php
$browser = get_browser(null, true);//get array of viewing browser information. Used in POST below.
//Address error handling
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~ E_NOTICE);
if (isset ($_POST['submit'])) {//Handle the form
if ($dbc = @mysql_connect ('localhost','root','root')) {
if (!@mysql_select_db ('feedback1')) {
die ('<p>Could not select the database because <b>' . mysql_error() . '</b></p>');
}
}else{
die('<p>Could not connect to MySQL because <b>' . mysql_error() . '</b></p>');
}
//Define the query. Note in this query we use the table "errors"
$query0 = "INSERT INTO errors (ID, words_omitted, jumbled_text, other, description, url, date_recorded, user, browser, operating_system)
VALUES (0, '{$_POST['words_omitted']}', '{$_POST['jumbled_text']}', '{$_POST['other']}', '{$_POST['description']}','{$_POST['url']}',NOW(),'{$_POST['user']}','{$_POST['browser']}','{$_POST['operating_system']}')";
//Execute the query
if (@mysql_query ($query0)) {
print '<p>The First form feedback has been recorded.</p>';
}else{
print "<p>Could not add entry because <b>" . mysql_error() . "</b> The query was $query0.</p>";
}
mysql_close();
}
?>
<!-- End process script and next display form-->
<!-- Begin Form 1 Errors--><div id="hideCategory1" class="formFrame">
<h2>Errors in the text</h2>
<p>Please check all that apply and add any description you can.</p>
<form action="TESTsingleformfeedback.php" method="post" name="errorInText">
<p><input name="words_omitted" type="checkbox" value="Words Missing" />Words Missing</p>
<p><input name="jumbled_text" type="checkbox" value="Jumbled Words" />Jumbled Text</p>
<p><input name="other" type="checkbox" value="Other" />Other - Please add details in the "Description" Box.</p>
<em>Description</em>
<p>Please add as much descripton as you can about the problem you noticed</p>
<textarea name="description" cols="40" rows="5"></textarea>
<p>Page Address:<input name="url" type="text" value="" id="targetURL" /></p>
<p>Date Recorded</p>
<p>User<input name="user" type="text" size="40" maxlength="100" /> </p>
<p>Browser<input name="browser" type="hidden" value="<?php echo $browser['browser'] ?>" /></p>
<p>Operating System<input name="operating_system" type="hidden" value="<?php echo $browser['platform'] ?>"/></p>
<input type="submit" name="submit" value="Add To Records" />
</form>
</div>
</div>
</body>
Javascript/jQuery 脚本是
$(document).ready(function() {
$('#target').each(function() {
var $link = $(this);
var $dialog = $('<div></div>')
.load($link.attr('href'))
.dialog({
autoOpen: false,
title: $link.attr('title'),
width: 600,
height: 500
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
});
});
如果有任何关于如何更改流程以便我可以使用模态表单的建议,我将不胜感激。
谢谢。
【问题讨论】:
-
您可以使用按钮或链接或提交按钮来触发 jQuery .ajax 并通过它提交表单,然后在 ajax 关闭模式之后。
-
@arma:感谢您的反馈。是的,我得出结论/了解到我的方法不正确,表单需要由 jquery 处理。
标签: php jquery jquery-ui forms modal-dialog