我正在爲新用戶和管理員的登記彈出形式。用戶將轉到new.php。該網站以表格的形式包含現有用戶的列表以及「創建新用戶」按鈕。點擊'創建新用戶'按鈕,它將顯示一個彈出窗體。提交表單後,頁面將自行刷新並更新現有的用戶表。如何將jquery ui模式表單提交到數據庫中?
做這一切,我使用jQuery UI的模式窗體演示。
,因爲它工作正常演示。但演示沒有保存數據。每當頁面刷新時,提交的數據將消失。它沒有去數據庫。我如何將數據傳遞到數據庫中?
new.php(對話)
<script type="text/javascript">
$(function() {
var name = $("#name"),
tel = $("#tel"),
email = $("#email"),
username = $("#username"),
password = $("#password"),
allFields = $([]).add(name) .add(tel) .add(email) .add(username) .add(password),
tips = $(".validateTips");
function updateTips(t) { tips.text(t).addClass("ui-state-highlight");
setTimeout(function() { tips.removeClass("ui-state-highlight", 1500); }, 500);
}
function checkLength(o, n, min, max) {
if (o.val().length > max || o.val().length < min) { o.addClass("ui-state-error");
updateTips("Length of " + n + " must be between " + min + " and " + max + ".");
return false;
}
else
{
return true;
}
}
function checkRegexp(o, regexp, n) {
if (!(regexp.test(o.val()))) { o.addClass("ui-state-error");
updateTips(n);
return false;
}
else
{
return true;
}
}
$("#dialog-form").dialog({
autoOpen: false,
height: 600,
width: 450,
modal: true,
buttons: {
"Create": function() {
var bValid = true;
allFields.removeClass("ui-state-error");
bValid = bValid && checkLength(name, "name", 3, 80);
bValid = bValid && checkLength(tel, "tel", 10, 11);
bValid = bValid && checkLength(email, "email", 6, 80);
bValid = bValid && checkLength(username, "username", 4, 20);
bValid = bValid && checkLength(password, "password", 5, 16);
bValid = bValid && checkRegexp(name, /^([a-zA-Z ])+$/, "Name may consist of a-z, space only.");
bValid = bValid && checkRegexp(tel, /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/, "eg. 012-976-9422");
bValid = bValid && checkRegexp(email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. [email protected]");
bValid = bValid && checkRegexp(username, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter.");
bValid = bValid && checkRegexp(password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9");
if (bValid) {
$("#users tbody").append("<tr>" +
"<td>" + name.val() + "</td>" +
"<td>" + tel.val() + "</td>" +
"<td>" + email.val() + "</td>" +
"<td>" + username.val() + "</td>" +
"<td>" + password.val() + "</td>" +
"</tr>");
$(this).dialog("close");
}
},
Cancel: function() { $(this).dialog("close"); }
},
close: function() { allFields.val("").removeClass("ui-state-error"); }
});
$("#create-user")
.button()
.click(function() {
$("#dialog-form").dialog("open");
});
});
</script>
</head>
new.php(形式&表)
<!--BUTTON-->
<button id="create-user">Create new user</button>
<!--DIALOG FORM-->
<div id="dialog-form" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="name">Full Name</label>
<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all">
<label for="tel">Phone Number</label>
<input type="tel" name="tel" id="tel" class="text ui-widget-content ui-corner-all"/>
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all">
<label for="name">Username</label>
<input type="text" name="username" id="username" class="text ui-widget-content ui-corner-all">
<label for="password">Password</label>
<input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all">
Admin
<input id="radio1" name="admin" type="radio" class="radio-btn" value="admin" />
User
<input id="radio2" name="user" type="radio" class="radio-btn" value="user" />
<script type="text/javascript" defer="defer">
<!--
if(document.getElementById){
if (option1 != ""){
// Radiobutton "No" should be selected.
document.getElementById('radio1').checked = false;
document.getElementById('radio2').checked = true;
}
else if (option2 != ""){
// Radiobutton "Yes" should be selected.
document.getElementById('radio1').checked = false;
document.getElementById('radio2').checked = true;
}
}
// -->
</script>
</fieldset>
</form>
</div>
<!--TABLE-->
<div id="users-contain" class="ui-widget">
<p style="float:left;">Existing Users:</p>
<br />
<table id="users" class="ui-widget ui-widget-content">
<thead>
<tr class="ui-widget-header ">
<th width="26%">Nama</th>
<th width="14%">No. Telefon</th>
<th width="25%">Email</th>
<th width="19%">Username</th>
<th width="16%">Password</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td></td>
<td>[email protected]</td>
<td>john89</td>
<td>johndoe1</td>
</tr>
</tbody>
</table>
</div>
請格式化你的代碼,以便我們可以看到它之前。 @jsve我已經編輯:) –
。將來,在發佈代碼之前格式化代碼會很好。 – Syaa
謝謝(我們不能幫助你,如果我們無法理解你的代碼。) –