Support

Account

Home Forums Front-end Issues Ability for a default checked radio button in a form Reply To: Ability for a default checked radio button in a form

  • I solved it. Thanks for your replays. I used a radio button field eventually (instead of the checkbox). here is the code:

    
        <div class="single-filter-type">
            <?php  $field = get_field_object('weather'); ?>
            <h3><?php echo $field['label'] ?></h3>
        <?php 
            $checked = ' checked="checked"';
            $weather_values = get_field('weather');                   
            if( $weather_values ):  
                    foreach( $field['choices'] as $k => $v ){ 
                        if(get_field('weather') == $v) { $checked = "checked";}else {$checked = '';} ?>     <label class="filter-checkbox-item" for="<?php  echo $v;  ?>">
                                <input type="radio" name="weather" value="<?php echo $v;  ?>" <?php echo $checked ?> >
                                <?php echo $v;  ?>
                            </label>
                <?php }   
    
           endif; 
       ?> 
        </div>