开发者

Display error when entire form is blank in CodeIgniter

开发者 https://www.devze.com 2022-12-12 22:54 出处:网络
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 req

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

精彩评论

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

关注公众号