开发者

Display error when entire form is blank in CodeIgniter

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 anyon开发者_StackOverflow中文版e know of an easy-ish solution for this? It seems like it should be so simple...

Thanks


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..


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜