Skip to content

Instantly share code, notes, and snippets.

@pporlan
Forked from mikedfunk/README.md
Last active May 15, 2018 18:56
Show Gist options
  • Select an option

  • Save pporlan/8316087 to your computer and use it in GitHub Desktop.

Select an option

Save pporlan/8316087 to your computer and use it in GitHub Desktop.

Revisions

  1. pporlan revised this gist May 15, 2018. 1 changed file with 6 additions and 9 deletions.
    15 changes: 6 additions & 9 deletions checkbox_helper.php
    Original file line number Diff line number Diff line change
    @@ -14,15 +14,12 @@
    * string or as an array.
    * @return void
    */
    function fix_unchecked($name)
    {
    function fix_unchecked($name) {
    $CI = & get_instance();
    if ($CI->input->post()) {
    if (!is_array($name)) { $name = array($name); }
    foreach ($name as $item) {
    if (!$CI->input->post($item)) { $_POST[$item] = 0; }
    }
    function fix_unchecked($name) {
    $CI = & get_instance();
    if ($CI->input->post()) {
    if (!is_array($name)) { $name = array($name); }
    foreach ($name as $item) {
    if (!$CI->input->post($item)) { $_POST[$item] = 0; }
    }
    }
    }
  2. pporlan revised this gist Jan 8, 2014. 2 changed files with 30 additions and 26 deletions.
    26 changes: 0 additions & 26 deletions checkbox.php
    Original file line number Diff line number Diff line change
    @@ -1,26 +0,0 @@
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    /**
    * @author Mike Funk
    * @link http://mikefunk.com
    * @email [email protected]
    * @file checkbox.php
    */

    /**
    * checkbox value fixer. If a checkbox is not checked, sets it's value
    * to zero.
    * @param mixed $name the checkbox form field name. Can be passed as a
    * string or as an array.
    * @return void
    */
    function fix_unchecked($name)
    {
    if (!is_array($name)) {$name = array($name);}
    foreach ($name as $item)
    {
    if (!$this->input->post($item)) {$_POST[$item] = 0;}
    }
    }
    /* End of file checkbox.php */
    /* Location: ./application/helpers/checkbox.php */
    30 changes: 30 additions & 0 deletions checkbox_helper.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    /**
    * @author Mike Funk
    * @modified_by Pedro Porlan
    * @email [email protected]
    * @file checkbox_helper.php
    */

    /**
    * checkbox value fixer. If a checkbox is not checked, sets it's value
    * to zero.
    * @param mixed $name the checkbox form field name. Can be passed as a
    * string or as an array.
    * @return void
    */
    function fix_unchecked($name)
    {
    function fix_unchecked($name) {
    $CI = & get_instance();
    if ($CI->input->post()) {
    if (!is_array($name)) { $name = array($name); }
    foreach ($name as $item) {
    if (!$CI->input->post($item)) { $_POST[$item] = 0; }
    }
    }
    }
    }
    /* End of file checkbox_helper.php */
    /* Location: ./application/helpers/checkbox_helper.php */
  3. @mikedfunk mikedfunk revised this gist Nov 2, 2012. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,4 @@ Just a tiny helper to help with checkboxes. When you uncheck a checkbox, it's va
    $this->load->helper('checkbox');

    // set post values to zero for unchecked boxes
    cb(['is_active', 'is_enabled', 'is_verified']);
    fix_unchecked(['is_active', 'is_enabled', 'is_verified']);
    2 changes: 1 addition & 1 deletion checkbox.php
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    * string or as an array.
    * @return void
    */
    function cb($name)
    function fix_unchecked($name)
    {
    if (!is_array($name)) {$name = array($name);}
    foreach ($name as $item)
  4. @mikedfunk mikedfunk revised this gist Nov 2, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,4 @@ Just a tiny helper to help with checkboxes. When you uncheck a checkbox, it's va
    $this->load->helper('checkbox');

    // set post values to zero for unchecked boxes
    cb(array('is_active', 'is_enabled', 'is_verified'));
    cb(['is_active', 'is_enabled', 'is_verified']);
  5. @mikedfunk mikedfunk revised this gist Nov 2, 2012. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,5 @@ Just a tiny helper to help with checkboxes. When you uncheck a checkbox, it's va

    $this->load->helper('checkbox');

    // checkbox names
    $checkboxes = array('is_active', 'is_enabled', 'is_verified');

    // set post values to zero for unchecked boxes
    cb($checkboxes);
    cb(array('is_active', 'is_enabled', 'is_verified'));
  6. @mikedfunk mikedfunk revised this gist Nov 2, 2012. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,13 @@
    # Checkbox Helper

    Just a tiny helper to help with checkboxes. When you uncheck a checkbox, it's value does not get sent in the form values. Instead of telling CodeIgniter you want to set this value to 0, it says "don't change it." This fixes that, one by one, by setting the value of the associated $_POST array item to zero. You can also pass in an array of checkbox names and it will do each one.
    Just a tiny helper to help with checkboxes. When you uncheck a checkbox, it's value does not get sent in the form values. Instead of telling CodeIgniter you want to set this value to 0, it says "don't change it." This fixes that, one by one, by setting the value of the associated $_POST array item to zero. You can also pass in an array of checkbox names and it will do each one.

    ## Usage

    $this->load->helper('checkbox');

    // checkbox names
    $checkboxes = array('is_active', 'is_enabled', 'is_verified');

    // set post values to zero for unchecked boxes
    cb($checkboxes);
  7. @mikedfunk mikedfunk created this gist Nov 2, 2012.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # Checkbox Helper

    Just a tiny helper to help with checkboxes. When you uncheck a checkbox, it's value does not get sent in the form values. Instead of telling CodeIgniter you want to set this value to 0, it says "don't change it." This fixes that, one by one, by setting the value of the associated $_POST array item to zero. You can also pass in an array of checkbox names and it will do each one.
    26 changes: 26 additions & 0 deletions checkbox.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    /**
    * @author Mike Funk
    * @link http://mikefunk.com
    * @email [email protected]
    * @file checkbox.php
    */

    /**
    * checkbox value fixer. If a checkbox is not checked, sets it's value
    * to zero.
    * @param mixed $name the checkbox form field name. Can be passed as a
    * string or as an array.
    * @return void
    */
    function cb($name)
    {
    if (!is_array($name)) {$name = array($name);}
    foreach ($name as $item)
    {
    if (!$this->input->post($item)) {$_POST[$item] = 0;}
    }
    }
    /* End of file checkbox.php */
    /* Location: ./application/helpers/checkbox.php */