CodeIgniter Forums
default 0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: default 0 (/showthread.php?tid=66869)



default 0 - twonno - 12-13-2016

hello guys
[redacted]non-English[/redacted], please help me
how to create a function if there is an empty form then automatically charged a value of 0 in the table using CodeIgniter

thanks


RE: default 0 - MuhamedAuda - 04-06-2017

(12-13-2016, 03:40 AM)twonno Wrote: hello guys
..., please help me
how to create a function if there is an empty form then automatically charged a value of 0 in the table using CodeIgniter

thanks

Hello, Can you please explain more of what you need it ? like example ..etc
Did you started a code ?


RE: default 0 - InsiteFX - 04-07-2017

Not sure if this is what your looking for, next time try to explain your problem better
so that we can understand what you are looking for.

You can add this to your controller etc;

PHP Code:
    /**
     * isChecked ()
     * ---------------------------------------------------------------------------
     *
     * $chkBoxName  - The name  of the form checkbox or radiobutton 
     * $chkBoxValue - The value of the form checkbox or radiobutton
     * 
     * EXAMPLE:
     * 
     * $formValue = $this->isChecked('chkBox1', '1');
     * 
     * @param  $chkBoxName  - the input name you set
     * @param  $chkBoxValue - the value that you set 1 0 yes no etc;
     * @return bool
     */
    
function isChecked($chkBoxName$chkBoxValue)
    {
        if ( ! empty(
$this->input->post[$chkBoxName]))
        {
            foreach (
$this->input->post[$chkBoxName] as $chkBoxVal)
            {
                if (
$chkBoxVal == $chkBoxValue)
                {
                    return 
true;
                }
            }
        }

        return 
false;
    } 

NOTE: A checkbox or radiobutton does not return any value when they are unchecked!
You may need to change it to 0 if you get a false returned from this method.