assign roles to users in custom drop down in signup form

Question

i have made html signup form in that i have usr roles drop down, while filling up signup form when i am selecting value from roles drop down its not getting updated in user_meta database, by default value is subscriber.thanks in advance. i want to update database value on dropsown selection. i have 2 values in drop down: user and photographer. other values i have removed.

<?php  
/* 
Template Name: Register Page
*/

get_header() ?>
<?php
global $wpdb;

if($_POST){
     $firstname= $wpdb->escape($_POST['fname']);
     $lastname= $wpdb->escape($_POST['lname']);
    $email= $wpdb->escape($_POST['email']);
     $confemail= $wpdb->escape($_POST['c_email']);

     $error=array();

    if(empty($firstname)){
         $error['firstname_empty']="username needed";
     }
     /*if(firstname_exists($firstname)){
     $error['firstname_exist']="firstname already exists";

     }

     if(lastname_exists($lastname)){
     $error['lastname_exist']="lastname already exists";

     }
*/

  if(!is_email($email)){
      $error['email_valid']="enter valid email id";

     }

     if(email_exists($email)){
      $error['email_existence']="email already exists";

     }

     if(strcmp($email, $confemail)){
      $error['email']="email doesnt match";

     }


     if(count($error)==0) {

    $user_id = wp_create_user($firstname,$lastname,$email);
      echo "you have registered succesfully.. "; 
     $user_info = get_userdata($user_id);
    // create md5 code to verify later
    $code = md5(time());
    // make it into a code to send it to user via email
    $string = array('id'=>$user_id, 'code'=>$code);
    // create the activation code and activation status
    update_user_meta($user_id, 'account_activated', 0);
    update_user_meta($user_id, 'activation_code', $code);
    // create the url
    $url = get_site_url(). '/email-verfication/?act=' .base64_encode( serialize($string));
    // basically we will edit here to make this nicer
    $html = 'Please click the following link <br/><a href="'.$url.'">'.$url.'</a>';
    echo "$html";

    wp_mail( $user_info->user_email, __('Email Subject','text-domain') , $html);
}
// send an email out to user
     exit();
     }
else{
        print_r($error);
        }
?>

<form name="signup-declaration" method="POST" id="signatory-sign-up-form">
    <div class="row">
      <div class="col-sm-6">
        <input type="text" name="fname" class="form-control" placeholder="First Name *">
      </div>
      <div class="col-sm-6">
        <input type="text" name="lname" class="form-control" placeholder="Last Name *">
      </div>
    </div><!--row ends-->
    <div class="row">
          <div class="col-sm-6">
        <input id="email" type="email" name="email" class="form-control" placeholder="Email *">
      </div>
      <div class="col-sm-6">
            <input type="email" name="c_email" class="form-control" placeholder="Confirm Email *">
      </div>
<?php global $wp_roles; ?>
Roles : <select name="role">
<?php foreach ( $wp_roles->roles as $key=>$value ): ?>
<option value="<?php echo $key; ?>"><?php echo $value['name']; ?></option>
<?php endforeach; ?>
</select>
</select>

 <br/>
<br/>
      <div class="col-sm-6">
    <input type="submit" name="new_user_submit" value="sign-up">
    </div><!--row ends-->
  </div>
</form>


<?php get_footer() ?>
0
priya 1 year 0 Answers 58 views 0

Leave an answer