views:

246

answers:

2

I'm trying to create a fairly simple form that has a few checkboxes and input fields and a textarea. Nothing is required by itself; however, if 'A' checkbox is checked, then 'A' input field is required (and so on for the couple other checkboxes I have).

I have the above functionality in place, but I'm having a tough time figuring out how to have an error returned if the form is submitted blank (since nothing is required by default).

Does anyone know of an easy-ish solution for this? It seems like it should be so simple...

Thanks

A: 

Just check if $_POST-array is empty, except for your submitbutton?

Ben Fransen
A: 

I assume that your using the form_validation class..

You will need to write a callback that does something like this:

function _checking()
{
    if (isset($_POST['a_checkbox']))
    {
        if (empty($_POST['a_text_field']))
        {
            $this->form_validation->set_message('_checking', 'this should not be empty');
            return FALSE;
        }
        return TRUE;
    }
}

I hope this is what you are looking for..

Thorpe Obazee