Welcome Guest, Not a member yet? Register   Sign In
using a callback with a checkbox
#1

[eluser]browntown[/eluser]
Okay...i'm stumped.

I have a form with a simple "do you authorize the release of this info" checkbox at the bottom of it. I want to display a custome error message: "You must authorize the release of this info..." instead of the standard "the authorized field is required". I'm using a callback to achieve the desired message.

I cannot get the callback to fire properly.

My checkbox looks like this:
Code:
$authorize = array('name'=>'authorize', 'id'=>'authorize', 'value'=>'accept', 'checked'=>FALSE, 'style'=>'');

My callback:
Code:
function authorizeForm()
            {
                if(!$this->input->post('authorize'))
                    {
                        $this->validation->set_message("authorizeForm", "You must authorize the release of this information.");
                        return FALSE;
                    }
                else
                    {
                        return TRUE;
                    }
            }

I've tried a ton of variations to check if the checkbox is checked..."
Code:
if($_POST['authorize'] =="")...
if(!isset($_POST['authorize'])...
if($this->input->post('authorize') != "accept")...

The weird thing is I can get the callback to fire if I do something like "if($this->input->post('authorize') == "accept")" and I check the checkbox...but if I do a "!= 'accept')"...it doesn't work.

Any ideas?
#2

[eluser]PauloBr[/eluser]
The callback function for checkbox, just execute if exists in "$_POST" array, so, just if checked.

You can use "required" rule to verify this, no?
#3

[eluser]browntown[/eluser]
yeah, it works if I used the "required" validation rule but I want to use a callback so I can customize the error message the user sees.

My call back works if I check to see if the callback is equal to "accept"...but does not work if I check to see if it is not equal to "accept".
#4

[eluser]Majd Taby[/eluser]
Go to http://ellislab.com/codeigniter/user-gui...ation.html and search for 'Setting Custom Error Messages'
#5

[eluser]browntown[/eluser]
I know how to set custom error messages. I can set custom error messages fine if the checkbox equals "accept"...but it doesn't seem to work if the checkbox does not equal "accept".
#6

[eluser]Majd Taby[/eluser]
ah, i'm sorry i didn't see that in your first post. To be honest I use my own form library, i'm not exactly sure how the helper and the validation library does it.




Theme © iAndrew 2016 - Forum software by © MyBB