开发者

codeigniter form validation set_value works only for the fields which have rules

Suppose if I have two fields in my form viz first_name and last_name

I have set the validation rule only for first_name.

set_value should work for both the fields regardless of rule ? right ?

For me it works only for the fields which have rules wit开发者_如何学Pythonh them !!!


set_value only works against the items you have chosen to validate using the form_validation class.

Easiest way is to pretend you are validating by adding this to your form validation config
array( 'field' => 'address1', 'label' => '', 'rules' => '' ),

There is a hack someone has done to the CI library but I haven't been able to find the documentation on that today...Or use this modification instead:

http://codeigniter.com/forums/viewthread/159535/#775628


There is simple solution of this issue. pass $_POST['your_field_name'] variable as a second parameter for fields those don't have any validation rule.

echo set_value('o_title',$_POST['o_title']);

It worked for me.


if you set the validation rule with just the first parameter it seems to work fine.

$this->form_validation->set_rules('city');

etc.

so there isn't a validation rule per se but it repopulates the field for you.


If you need set_checkbox support see this code.

MY_form_helper.php with set_checkbox support


some times i use fake rule like trim or callback just to repopulate the filed data

$this->form_validation->set_rules('city','City','trim');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜