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>

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.

result should be 2 radio buttons like below

  • Voter
  • Writer

this is what showen on the page

38b24846cf8e4ac253603609478cbc16

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.

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>

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
}
?>
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.

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
}
?> 

in simple words this code works fine

Does that mean that the code works fine now?

yes the code is working.
Many thanks to broj1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.