Welcome Guest, Not a member yet? Register   Sign In
How to repopulate update form and radio inputs
#5

[eluser]porquero[/eluser]
I set forms this:

[controller]
Code:
$data = array(
'genre_selected' => 'male',
'genres' => array(
  'male',
  'female',
),
);

[view]
Code:
// Filed name
$field = 'genre';

// Set selected radio
$selected = array_fill_keys($genres, false);
$selected[$genre_selected] = true;

// Generate radios
foreach ($genres as $genre) {
    // Slug for id
    $radio_id = url_title($field . '_' . $genre, 'dash', true);
    // Label
    echo form_label($genre, $radio_id)
    // Show radio checking only selected. without if!!! :)
    . form_radio($field, $genre, $selected[$genre], 'id="' . $radio_id . '"');
}

Only you need change the $genre_selected variable and will checked correct radio.


Messages In This Thread
How to repopulate update form and radio inputs - by El Forum - 03-02-2012, 06:29 AM
How to repopulate update form and radio inputs - by El Forum - 03-02-2012, 01:01 PM
How to repopulate update form and radio inputs - by El Forum - 03-02-2012, 01:42 PM
How to repopulate update form and radio inputs - by El Forum - 03-02-2012, 01:47 PM
How to repopulate update form and radio inputs - by El Forum - 03-02-2012, 02:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB