Welcome Guest, Not a member yet? Register   Sign In
Sending 0 for value for checkbox being unchecked
#1

[eluser]xtremer360[/eluser]
I'm trying to figure out how to handle this situation. I have the following line for logging in a user however with this situation the remember post parameter might not be set upon form submission so i'd still like it to send 0 as its value with this function.

Code:
if ($this->kowauth->login($this->input->post('username'), $this->input->post('password'),
                            $this->input->post('remember'))) {}

Here's the form element:

Code:
<?php
if(isset($_COOKIE['xtrcook']))
{
    echo form_label((form_checkbox('remember', '1', TRUE)) . 'Remember Me!', 'remember');
}
else
{
     echo form_label((form_checkbox('remember', '1', FALSE)) . 'Remember Me!', 'remember');
}
?>
#2

[eluser]InsiteFX[/eluser]
CodeIgniter Users Guide - Form Helper - form_checkbox() - set_checkbox()

Permits you to display a checkbox in the state it was submitted. The first parameter must contain the name of the checkbox, the second parameter must contain its value, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE). Example:
Code:
<input type="checkbox" name="mycheck" value="1" <?php echo set_checkbox('mycheck', '1'); ?> />
<input type="checkbox" name="mycheck" value="2" <?php echo set_checkbox('mycheck', '2'); ?> />
#3

[eluser]xtremer360[/eluser]
So what's the difference between giving it a value of 1 AND have a set_checkbox tag.
#4

[eluser]xtremer360[/eluser]
I ask because I still don't understand that last part.
#5

[eluser]InsiteFX[/eluser]
Because if a checkbox or radio button is not checked it will return nothing to you!
It is empty no value!

0 = FALSE
#6

[eluser]xtremer360[/eluser]
I understand the fact that when I submit a form that has my check mark unchecked but I want to make it that when it is unchecked the it gives me a value of 0
#7

[eluser]InsiteFX[/eluser]
Here is quick fix for you:
Code:
<input type="hidden" name="box1" value="0" />
<input type="checkbox" name="box1" value="1" />




Theme © iAndrew 2016 - Forum software by © MyBB