I am using the 'wpestate' theme for my website but I would like to add some custom fields for my user registration. So I tried the following code to extend it:
The probelem: When I try to register a new account it seems the page is doing only a page refresh that's it. It's no problem that it is not working with AJAX currently but a normal registration would be nice.
This is the logic to validate a few fields.. But I think it never goes in there.
////////////////////////////////////////////////////////////////////////////////
/// Ajax Register function
////////////////////////////////////////////////////////////////////////////////
add_action( 'wp_ajax_nopriv_ajax_register_form', 'ajax_register_form' );
// add_action( 'wp_ajax_ajax_register_form', 'ajax_register_form' );
function ajax_register_form(){
//check_ajax_referer( 'register_ajax_nonce','security-register');
$user_email = trim( $_POST['user_email_register'] ) ;
///echo $user_email;
$user_name = trim( $_POST['user_email_register'] ) ;
$firstname = trim( $_POST['first_name'] ) ;
$lastname = trim( $_POST['last_name'] ) ;
$street = trim( $_POST['rpr_street'] ) ;
$number = trim( $_POST['rpr_number'] ) ;
$city = trim( $_POST['rpr_city'] ) ;
$country = trim( $_POST['rpr_country'] ) ;
$phone = trim( $_POST['rpr_phone'] ) ;
if ($user_email=='' || $lastname == '' || $firstname =='' || $street == '' || $number == '' || $city == '' || $city == '' || $country == '' || $phone == ''){
print __('All fields are required.', 'wpestate');
exit();
}
if(filter_var($user_email,FILTER_VALIDATE_EMAIL) === false) {
print __('The email doesn\'t look right !','wpestate');
exit();
}
$domain = substr(strrchr($user_email, "@"), 1);
if( !checkdnsrr ($domain) ){
print __('The email\'s domain doesn\'t look right.','wpestate');
exit();
}
$user_id = email_exists( $user_email );
if ($user_id){
print __('Username already exists. Please choose a new one.','wpestate');
exit();
}
if ( !$user_id and email_exists($user_email) == false ) {
$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
$user_id = wp_create_user( $user_email, $random_password, $user_email );
if ( is_wp_error($user_id) ){
print_r($user_id);
}else{
print __('Your account is waiting for approval, you will receive a mail once your account is approved by Sophima.','wpestate');
wpestate_update_profile($user_id);
wpestate_wp_new_user_notification( $user_id, $random_password ) ;
if('yes' == esc_html ( get_option('wp_estate_user_agent','') )){
wpestate_register_as_user($user_name,$user_id);
}
}
} else {
print __('Email already exists. Please choose a new one.','wpestate');
}
die();
}
This is the part where I generate the form fields:
///////////////////////////////////////////////////////////////////////////////////////////
// register form function
///////////////////////////////////////////////////////////////////////////////////////////
/**
* @param $attributes
* @param null $content
* @return string
*
* <div class="row">
<label for="user_login">'.__('Username','wpestate').'</label>
<input type="text" name="user_login_register" id="user_login_register" class="input" value="" size="20" />
</div>
*/
function register_form_function($attributes, $content = null) {
$return_string='
<form action="" method="POST">
<div class="login_form">
<div class="loginalert" id="register_message_area" ></div>
<div class="row">
<label for="first_name">'.__('Firstname','wpestate').'</label>
<input type="text" name="first_name" id="first_name" class="input" value="" size="20" />
</div>
<div class="row">
<label for="last_name">'.__('Lastname','wpestate').'</label>
<input type="text" name="last_name" id="last_name" class="input" value="" size="20" />
</div>
<div class="row">
<label for="user_email">'.__('Email','wpestate').'</label>
<input type="text" name="user_email_register" id="user_email_register" class="input" value="" size="20" />
</div>
<div class="row">
<label for="rpr_street">'.__('Street','wpestate').'</label>
<input type="text" name="rpr_street" id="rpr_street" class="input" value="" size="20" />
</div>
<div class="row">
<label for="rpr_number">'.__('Number','wpestate').'</label>
<input type="text" name="rpr_number" id="rpr_number" class="input" value="" size="20" />
</div>
<div class="row">
<label for="rpr_city">'.__('City','wpestate').'</label>
<input type="text" name="rpr_city" id="rpr_city" class="input" value="" size="20" />
</div>
<div class="row">
<label for="rpr_country">'.__('Country','wpestate').'</label>
<input type="text" name="rpr_country" id="rpr_country" class="input" value="" size="20" />
</div>
<div class="row">
<label for="rpr_phone_number">'.__('Phone number','wpestate').'</label>
<input type="text" name="rpr_phone_number" id="rpr_phone_number" class="input" value="" size="20" />
</div>
<p id="reg_passmail">'.__('A password will be e-mailed to you','wpestate').'</p>
'. wp_nonce_field( 'register_ajax_nonce', 'security-register' ).'
<p class="submit"><input type="submit" name="wp-submit" id="wp-submit-register" class="btn vernil small" value="'.__('Register','wpestate').'" /></p>
</div>
</form>
';
return $return_string;
}
Thanks a lot! For every assistance.