Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9252135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:52:11+00:00 2026-06-18T10:52:11+00:00

i generate radio buttons using Yii the code looks like <span class=gender> <?php echo

  • 0

i generate radio buttons using Yii
the code looks like

    <span class="gender">
       <?php echo CHtml::activeRadioButton($model,'gender',array('value' => 'male')); ?>
    </span>

  <span class="gender">
       <?php echo CHtml::activeRadioButton($model,'gender',array('value' => 'female')); ?>
  </span>

It’s generate next HTML code

    <span class="gender">
<input id="ytweb\models\register_gender" type="hidden" value="0" name="web\models\register[gender]">

<input value="male" class="male" name="web\models\register[gender]"id="web\models\register_gender" type="radio"></span>

<span class="gender">
<input id="ytweb\models\register_gender" type="hidden" value="0" name="web\models\register[gender]">

<input value="female" class="female" name="web\models\register[gender]" id="web\models\register_gender" type="radio">

</span>

when i get POST from this form, if i checked female it returns female, but if i cheked male it returns 0. I think it is because of identical inputs ids. But how can i avoid it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:52:12+00:00Added an answer on June 18, 2026 at 10:52 am

    You can configure activeRadioButton to not output the “guard input” with value 0. Do this by passing the parameter 'uncheckValue' => null as part of your options array:

    echo CHtml::activeRadioButton($model,'gender',
        array('value' => 'male', 'uncheckValue' => null));
    echo CHtml::activeRadioButton($model,'gender',
       array('value' => 'female', 'uncheckValue' => null));
    

    That said, using activeRadioButtonList is the best choice here. You can configure its template parameter to specify your custom HTML:

    $genders = array('male' => 'male', 'female' => 'female');
    $options = array(
        'template'     => '<span class="gender">{input</span>',
        'uncheckValue' => null,
    );
    echo CHtml::activeRadioButtonList($model, 'genger', $genders, $options);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To generate the following markup: <label class=foo>Bar</label> The PHP will look something like: <?php
Im using RadioButtonList to generate my radio buttons, in a MVC Razor project. Here's
friends, i am using following code to display list with radio buttons now i
I'm dynamically generating radio buttons in my code behind and assigning javascript to them
I am using PHP MYSQL to generate a small multi page quiz. I am
I would like to generate a SQLFORM with radiobuttons using the radiobutton widget as
I want to validate my form using jQuery. It has groups of radio buttons.
I'm making dynamic radio buttons by using ASP.NET. Where there a validation control that
I am using the following code in xml to generate two RadioButtons with a
I have a set of radio buttons that are dynamically generated (via JSON call):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.