Welcome Guest, Not a member yet? Register   Sign In
callback on checkbox not working
#1

[eluser]CIfan1000[/eluser]
Hi guys!

I have the following in a controller:

Code:
// Define the validation rules for each field:
        // The names must be the field names in the form:
        $rules['RegisterUsername']         = "trim|required|min_length[5]|max_length[12]|xss_clean|alpha_dash";
    $rules['RegisterUserEmail']         = "trim|required|valid_email";
    $rules['RegisterUserPassword']     = "trim|required|min_length[5]|max_length[12]|xss_clean|alpha_dash|md5";
    $rules['RegisterUserPassword2']     = "trim|required|min_length[5]|max_length[12]|xss_clean|matches[RegisterUserPassword]|alpha_dash|md5";
    $rules['CheckboxUserAgreement']     = "callback_CheckboxUserAgreement_validate";

And then later in the same controller:

Code:
// ----------------------------------------------------------------------------
        // Define callback function used in validation above:
       function CheckboxUserAgreement_validate($str)
           {
                // Check if the CheckboxUserAgreement is checked:
                if (isset ($_POST ["CheckboxUserAgreement"]))
                    {
                        echo "true";
                         return TRUE;
                    }
                else
                    {
                     $this->validation->set_message('CheckboxUserAgreement_validate', 'You must agree to the User Agreement');
                     return FALSE;
                    }

            // End of CheckboxUserAgreement_validate function
            }

But the callback function does not seem to get called.

Any assistance or other suggestions as to how to validate a single checkbox would be very much appreciated. Thanks!
#2

[eluser]faxtion[/eluser]
[quote author="CIfan1000" date="1223860679"]

Code:
// ----------------------------------------------------------------------------
        // Define callback function used in validation above:
       function CheckboxUserAgreement_validate($str)
           {
                // Check if the CheckboxUserAgreement is checked:
                if (isset ($_POST ["CheckboxUserAgreement"]))
                    {
                        echo "true";
                         return TRUE;
                    }
                else
                    {
                     $this->validation->set_message('CheckboxUserAgreement_validate', 'You must agree to the User Agreement');
                     return FALSE;
                    }

            // End of CheckboxUserAgreement_validate function
            }

Might be a long shot but have you tried the following:

Code:
if ($_POST ["CheckboxUserAgreement"] == '0')
        {
                     $this->validation->set_message('CheckboxUserAgreement_validate', 'You must agree to the User Agreement');
                     return FALSE;
        }
        else
        {
            return TRUE;
        }




Theme © iAndrew 2016 - Forum software by © MyBB