create registration form in wordpress
page createform create
template name
header footer collect and then form validation
then count ==0
then create table
<?php
/*Template Name:registration
*/
get_header();
global $wpdb;
/*form validation*/
if($_POST){
$username= $wpdb->escape($_POST['txtUsername']);
$email= $wpdb->escape($_POST['txtEmail']);
$password= $wpdb->escape($_POST['txtPassword']);
$Confirmpassword= $wpdb->escape($_POST['txtConfirmPassword']);
$error = array();
/*check no space username*/
if(strpos($username,' ') !==FALSE){
$error['username_space'] = "username has no space";
}
if(empty($username)){
$error ['$username_empty'] = "Nedded username must";
}
if(username_exists($username)){
$error['username_exists'] = "username already exists";
}
/*email or valid or not*/
if(!is_email($email)){
$error['email_valid'] = "Email has no valid value";
}
if(email_exists($email)){
$error['email_existence'] = "Email all ready exits";
}
/*password*/
if(strcmp($password, $Confirmpassword)!== 0){
$error['password'] = "not match";
}
if(count($error) == 0){
wp_create_user($username,$password,$email);
echo "user create successfully";
exit();
}else{
print_r($error);
}
// print_r($error);
}
?>
<form method="POST">
<p>
<label>Enter Username</label>
<div>
<input type="text" id="txtUsername" name="txtUsername" placeholder="enter Username">
</div>
</p>
<p>
<label >Enter Email</label>
<div>
<input type="email" id="txtEmail" name="txtEmail" placeholder="enter Email">
</div>
</p><p>
<label>Enter Password</label>
<div>
<input type="password" id="txtPassword" name="txtPassword" placeholder="enter Password">
</div>
</p>
<p>
<label >Enter Confirmpassword</label>
<div>
<input type="password" id="txtConfirmPassword" name="txtConfirmPassword" placeholder="enter Username">
</div>
</p>
<input type="submit" name="btnsubmit" value="submit">
</form>
<?php
get_footer();
?>
No comments:
Post a Comment