Welcome Guest, Not a member yet? Register   Sign In
How to Keep maintain Radio button and chekbox Values After submit in form
#7

(05-07-2015, 07:22 AM)mwhitney Wrote: Ignoring the HTML, here's an example of how to do this, assuming that you pass the selected value of marital_status to the view as $marital_status and the values of the checked checkboxes in an array as $hobbies.


PHP Code:
<?php

$selectedStatus 
= isset($marital_status) ? $marital_status '-1';
$selectedHobbies = isset($hobbies) ? $hobbies : array();

$status = array(
    "-1"        => "Select One",
    "Married"   => "Married",
    "Unmarried" => "Unmarried",
    "divorced"  => "Divorced",
);
$statusDropdown = array(
    'name'  => 'marital_status',
    'id'    => 'marital_status',
    'class' => 'status',
);
$hobbyCheckboxes = array(
    'cricket' => array(
        'name'    => 'hobbies',
        'id'      => 'hobbies_cricket',
        'value'   => 'Cricket',
        'checked' => in_array('Cricket'$selectedHobbies),
    ),
    'chess' => array(
        'name'    => 'hobbies',
        'id'      => 'hobbies_chess',
        'value'   => 'Chess',
        'checked' => in_array('Chess'$selectedHobbies),
    ),
    'kabbadi' => array(
        'name'    => 'hobbies',
        'id'      => 'hobbies_kabbadi',
        'value'   => 'Kabbadi',
        'checked' => in_array('Kabbadi'$selectedHobbies),
    ),
);

echo 
form_dropdown($statusDropdown$status$selectedStatus);

echo 
form_checkbox($hobbyCheckboxes['cricket']);
echo 
form_checkbox($hobbyCheckboxes['chess']);
echo 
form_checkbox($hobbyCheckboxes['kabbadi']);

/* OR, if you don't have 'value' and 'checked' in $hobbyCheckboxes */
echo form_checkbox($hobbyCheckboxes['cricket'], 'Cricket'in_array('Cricket'$selectedHobbies));
echo 
form_checkbox($hobbyCheckboxes['chess'], 'Chess'in_array('Chess'$selectedHobbies));
echo 
form_checkbox($hobbyCheckboxes['kabbadi'], 'Kabbadi'in_array('Kabbadi'$selectedHobbies)); 

How to keep maintain the radio button values .... after submit ..? 
Selected And check box values Ok .. I have Problem With Radio buttons ...
Manikanta
Reply


Messages In This Thread
RE: How to Keep maintain Radio button and chekbox Values After submit in form - by Chandini - 05-07-2015, 09:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB