• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
form_checkbox and set_checkbox

#10
[eluser]bhumes[/eluser]
set_checkbox returns ' checked="checked"' or an empty string, which is no good for us, as form_checkbox is expecting a boolean. So, I created a replacement function in my helper file. Code is below:

Code:
function set_checkbox($field = '', $value = '', $default = FALSE)
{
  if ( ! isset($_POST[$field]))
  {
   if (count($_POST) === 0 AND $default == TRUE)
   {
    return TRUE;
   }
   return FALSE;
  }

  $field = $_POST[$field];

  if (is_array($field))
  {
   if ( ! in_array($value, $field))
   {
    return FALSE;
   }
  }
  else
  {
   if (($field == '' OR $value == '') OR ($field != $value))
   {
    return FALSE;
   }
  }

  return TRUE;
}

Basically, I am returning TRUEs and FALSEs instead of the aforementioned strings. Works perfectly. Hope this helps someone..


Messages In This Thread
form_checkbox and set_checkbox - by El Forum - 03-18-2011, 08:46 AM
form_checkbox and set_checkbox - by El Forum - 03-18-2011, 09:27 AM
form_checkbox and set_checkbox - by El Forum - 03-18-2011, 10:17 AM
form_checkbox and set_checkbox - by El Forum - 03-18-2011, 10:41 AM
form_checkbox and set_checkbox - by El Forum - 03-18-2011, 11:02 AM
form_checkbox and set_checkbox - by El Forum - 03-18-2011, 03:17 PM
form_checkbox and set_checkbox - by El Forum - 03-18-2011, 03:25 PM
form_checkbox and set_checkbox - by El Forum - 03-18-2011, 07:13 PM
form_checkbox and set_checkbox - by El Forum - 03-21-2011, 03:21 PM
form_checkbox and set_checkbox - by El Forum - 09-04-2012, 02:10 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.