Can i Use validation rules in CI on the same element twice

回眸只為那壹抹淺笑 提交于 2020-01-06 15:11:25

问题


I Have Defined my all rules in a form_validation file in config file

e.x

$config = array(
     'basic' => array(
        array(
            'field' => 'name',
            'label' => 'Name',
            'rules' => 'alpha'
        ),
         array(
            'field' => 'age',
            'label' => 'Age',
            'rules' => 'alpha'
        ),
          array(
            'field' => 'city',
            'label' => 'City',
            'rules' => 'alpha'
        )

     ),

      'mandate' => array(
         array(
            'field' => 'name',
            'label' => 'Name',
            'rules' => 'required'
        ),
         array(
            'field' => 'age',
            'label' => 'Age',
            'rules' => 'required'
        ),
         array(
            'field' => 'city',
            'label' => 'City',
            'rules' => 'required'
        ),

    ),
);


 $config["submitfinal"] = array_merge($config['basic'], $config['mandate']);

What i have been trying to achieve is there are two buttons in which one button is called (savenow) where when the user presses it, it should validate only for nonempty data and the other button is (save and complete) when the user presses it ,it should validate for non empty as well as other rule sets , so i had two groups defined separately and called them for (savenow feature) and when i try to combine both the groups the validation of basic group seems to be not working

Note: I Have applied validation on the same fieldnames in both the groups can you suggest me like how to go further on implementing save and complete feature.


回答1:


keep them seperate mean no need to merge them, just update mandate array as

'mandate' => array(
         array(
            'field' => 'name',
            'label' => 'Name',
            'rules' => 'required|alpha'
        ),
         array(
            'field' => 'age',
            'label' => 'Age',
            'rules' => 'required|alpha'
        ),
         array(
            'field' => 'city',
            'label' => 'City',
            'rules' => 'required|alpha'
        ),

    ),

then just call one specific group on click function.



来源:https://stackoverflow.com/questions/29789238/can-i-use-validation-rules-in-ci-on-the-same-element-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!