[英]jQuery pop-up with php form validation
i have a registration page 我有一个注册页面
<form class="register" action="regist.php" method="post" >
<h3>Register</h3>
<div class="column">
<div>
<label>First Name:</label>
<input type="text" name="f_name"/>
<span ></span>
</div>
<div>
<label>Last Name:</label>
<input type="text" name="l_name"/>
<span class="error">This is an error</span>
</div>
<div>
<label>mobile:</label>
<input type="text" name="mobile"/>
<span class="error">This is an error</span>
</div>
</div>
<div class="column">
<div>
<label>Username:</label>
<input type="text"name="user"/>
<span >This is an error</span>
</div>
<div>
<label>Email:</label>
<input type="text" name="email"/>
<span class="error">This is an error</span>
</div>
<div>
<label>Password:</label>
<input type="password" name="pass"/>
<span class="error">This is an error</span>
</div>
</div>
<div class="bottom">
<div class="remember">
</div>
<input type="submit" value="Register" name="submet" />
<a href="index.html" rel="login" class="linkform">You have an account already? Log in here</a>
<div class="clear"></div>
</div>
</form>
that use jquery bpopup 使用jQuery bpopup
$(function() {
// Binding a click event
// From jQuery v.1.7.0 use .on() instead of .bind()
$('#my-button').bind('click', function(e) {
// Prevents the default action to be triggered.
e.preventDefault();
// Triggering bPopup when click event is fired
$('#element_to_pop_up').bPopup();
});
}
so when some one click register the form will pop up every thing work fine the problem is that i cant do validation to the form because when i click register after filling the form the pop up will disappear so i cant make the validation on the same form 因此,当我单击一次注册时,表单将弹出所有正常工作的问题是我无法对表单进行验证,因为当我在填写表单后单击注册时,弹出窗口将消失,因此我无法在同一表单上进行验证
i tried 1 to make another pop up that show the error but the data wont pass to the new popup 2 to make the action $_SERVER['self_request']
can some one help me withe this please i have a project for my college i nee to do it in 3 dayes 我试过1使另一个弹出窗口显示错误,但数据不会传递给新的弹出窗口2以使操作
$_SERVER['self_request']
可以有人帮助我,请给我我大学的一个项目在三天内完成
what i need is a validation for the form in the same page or another popup before send it to the MySQL script 我需要在将表单发送到MySQL脚本之前对同一页面或其他弹出窗口中的表单进行验证
Make an php page ( here called validation.php ) that uses the GET function to get the info... 制作一个使用GET函数获取信息的php页面(此处称为validate.php)。
Then set some ID's on the input fields... 然后在输入字段上设置一些ID ...
And then make an function like this: 然后制作一个这样的函数:
function checkAll(){
var firstName = document.getElementById("f_name").value();
var lastName = document.getElementById("l_name").value();
$.get( "validation.php?f_name=" + firstName + "&l_name=" + lastName, function( response ) {
// console.log( response ); // server response
response = response.trim();
if(response == 1){
alert("Everything is alright");
} else{
alert(response);
return false;
}
});
}
And change your form to this: 并将表单更改为:
<form class="register" action="regist.php" method="post" onSubmit="checkAll();">
Now the key is that in the validation.php ,if everything works fine then you can echo value 1, and when something is not alright, you echo the error code ( or any code, and then with an switch clause you can dynamically add the error to your form). 现在的关键是,在validation.php中,如果一切正常,则可以回显值1,而在某些情况不正常时,可以回显错误代码(或任何代码),然后使用switch子句可以动态添加错误的形式)。
The return false
prevents the form from submitting... return false
阻止表单提交...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.