how to use ajaxform plugin and php
Question
i'm trying to use ajaxform plugin with php , please help me I couldn't catch my goal which is
1- the user fill this form ,(( even I want the user to upload a picture but I did my best in coding with no much result so I deleted input type="file" , if you have an idea how to handle this in ajaxform and php please edit my form ))
< form name="signup" autocomplete="on" id="signup_form" method="get" action="signup_feed.php">
<fieldset>
<legend>Sign Up</legend>
<label class="span-4" >First Name*:</label> <input type="text" id="u_fname" name="u_fname"/><br/>
<label class="span-4">Last Name*:</label><input type="text" id="u_lname" name="u_lname"/><br/>
<label class="span-4">Email*:</label><input type="email" id="u_email" name="u_email"/><br/>
<label class="span-4">Password*:</label><input type="password" id="u_pass" name="u_pass"/></br>
<label class="span-4">Re-type Password*:</label><input type="password" name="u_re_pass"/></br>
<label class="span-4">Phone no.:</label><input type="tel" id="u_phone" name="u_phone" /><br/>
<input type="submit" value="Sign up" class="button" id="sign_up_btn"/>
</fieldset>
</form>
2- using ajaxform I want values of above form to be submitted , after that there's a countdown 5 seconds to redirect to sign_in.php page
var options = {
target:'#sign_up_div',
success: function(){
$('#sign_up_div').replaceWith("<div id='signup_success_msg' class='success'></div>");
$('#signup_success_msg').html("<h3>You have registered ! </h3>")
.hide()
.fadeIn(1500, function() {
$('#signup_success_msg').append("<img id='checkmark' src='img/icon-check.png' />");
});
$('#signup_success_msg').append('<p>please sign up</p>').delay( 2500 ).fadeOut(1500, function() { $(this).remove(); });
},
url:signup_feed.php,
type:post
};
$('#signup_form').submit(function() {
// inside event callbacks 'this' is the DOM element so we first
// wrap it in a jQuery object and then invoke ajaxSubmit
$(this).ajaxSubmit(options);
// !!! Important !!!
// always return false to prevent standard browser submit and page navigation
return false;
});
3- php use redbeansphp to store data
$user = R::dispense( 'user' );
$user->u_fname=$_GET['u_fname'];
$user->u_lname=$_GET['u_lname'];
$user->u_email=$_GET['u_email'];
$user->u_pass=$_GET['u_pass'];
$user->u_phone=$_GET['u_phone'];
$id = R::store($user);
echo "<p> Thank you for resigteration! Please sign in </p><p id='countdown'></p>
<p>if you still see this page , please <label><a href='sign_in.php'>click here</a></label> </p>";
I'm still new at Jquery but I really want to achieve these goals in my forms ..
Solution
$('form[name="formName"]').ajaxForm({
success : function (response) {
alert("submitted");
}
}).submit()
This is working ajaxform in my project. try this.
OTHER TIPS
You can add: setTimeout(function() { location.href = "TARGET_URL"; }, 5000;
inside success: function() { }