0

i using this code to display radio buttons for selection. somehow the its not working correctly, plz guide on this issue.
thanks in advance.

 <div class="register-section" id="user-role-section">
    <label for="wp_rar_user_role"><?php echo $this->wp_rar_role_label; ?></label>
    <?php
    foreach($this->wp_selected_rar_roles as $role) {
      ?>
     <input type="radio" name="wp_rar_user_role" id="wp_rar_user_role" class="input select" value="<?php echo $role; ?>" /> <label>
        <?php echo $wp_roles->roles[$role]['name']; ?>
      </label>
      <?php
    }
    ?>

    </div>
2
Contributors
9
Replies
27
Views
3 Years
Discussion Span
Last Post by net4earning
0

Seems like $role is an array and therefore won't display as a string. Can you post the contents of the $role - you do this by using print_r($role).

Edit: I forgot to mention I am not a WP expert.

Edited by broj1

0

result should be 2 radio buttons like below

  • Voter
  • Writer

this is what showen on the page

38b24846cf8e4ac253603609478cbc16

Edited by net4earning

0

Ups, I wrongly interpreted your code, I am sory for that. Please disregard my post above.

Can you post the html code for both radio buttons that gets generated, please.

0

this is the HTML produced by above code.

<p>
    <label for="wp_rar_user_role">Account type<br />
          <input type="radio" name="wp_rar_user_role" id="wp_rar_user_role" class="input select"

                 value="voter" /> <label>

        Voter      </label>
                   value="writer" /> <label>

        Writer      </label>
          </label>
</p>
0

Sory for late reply, I was away. Can you post the contents of the $this->wp_selected_rar_roles and $wp_roles->roles arrays. You can use this code:

<?php
// show contents of $this->wp_selected_rar_roles
echo '<pre>$this->wp_selected_rar_roles' . print_r($this->wp_selected_rar_roles, 1) . "</pre>";

foreach($this->wp_selected_rar_roles as $role) {

    // show contents of $wp_roles->roles
    echo '<pre>$wp_roles->roles' . print_r($wp_roles->roles, 1) . "</pre>";

?>
<input type="radio" name="wp_rar_user_role" id="wp_rar_user_role" class="input select" value="<?php echo $role; ?>" /> <label>
<?php echo $wp_roles->roles[$role]['name']; ?>
</label>
<?php
}
?>

Edited by broj1

0
echo '<pre>$this->wp_selected_rar_roles' . print_r($this->wp_selected_rar_roles, 1) . "</pre>";

showes

$this->wp_selected_rar_rolesArray
(
    [0] => voter
    [1] => writer
)

this code

echo '<pre>$wp_roles->roles' . print_r($wp_roles->roles, 1) . "</pre>";

Showes a long list of user powers.

then it showes correct radio button.

0

in simple words this code works fine.

<?php
// show contents of $this->wp_selected_rar_roles
// echo '<pre>$this->wp_selected_rar_roles' . print_r($this->wp_selected_rar_roles, 1) . "</pre>";
foreach($this->wp_selected_rar_roles as $role) {
    // show contents of $wp_roles->roles
  //  echo '<pre>$wp_roles->roles' . print_r($wp_roles->roles, 1) . "</pre>";
?>
<input type="radio" name="wp_rar_user_role" id="wp_rar_user_role" class="input select" value="<?php echo $role; ?>" /> <label>
<?php echo $wp_roles->roles[$role]['name']; ?>
</label>
<?php
}
?> 
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.