Welcome Guest, Not a member yet? Register   Sign In
Trying to set a checkbox here and i'm going loco
#5

[eluser]Michael Wales[/eluser]
Here's how I would do it - beginning to end:

Code:
// This array has a list of all your checkboxes
$extras = array('web', 'ftp', 'ssl');
foreach ($extras as $option) {
  // Check if there is a session variable for that option
  $check_status[$option] = '';
  if ($this->session->userdata($option)) {
    $check_status[$option] = ' CHECKED';
  }
}

To display form:
Code:
foreach ($extras as $option) {
  echo '<input type="checkbox" name="'.$option.'"'.$check_status[$option].' />'.$option.';
}

Just remember - when the form is submitted that boxes that are unchecked will not be sent to the form processor. I find the easiest way to handle this is to set all of the session (or database, however you are doing it) to FALSE and then go through and assign the ones that were passed to the form handler to TRUE.


Messages In This Thread
Trying to set a checkbox here and i'm going loco - by El Forum - 11-27-2007, 10:41 AM
Trying to set a checkbox here and i'm going loco - by El Forum - 11-27-2007, 10:53 AM
Trying to set a checkbox here and i'm going loco - by El Forum - 11-27-2007, 10:59 AM
Trying to set a checkbox here and i'm going loco - by El Forum - 11-27-2007, 12:06 PM
Trying to set a checkbox here and i'm going loco - by El Forum - 11-27-2007, 12:46 PM
Trying to set a checkbox here and i'm going loco - by El Forum - 11-27-2007, 01:58 PM
Trying to set a checkbox here and i'm going loco - by El Forum - 11-28-2007, 05:58 AM
Trying to set a checkbox here and i'm going loco - by El Forum - 11-28-2007, 06:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB