How to fill out a form field without setting a rule, as required in Codeigniter?

When I try to fill out a form field that is not required in form validation, it is not populated. Say I have a field, but I don’t want it to be required, but I want it to be populated. How can I do it? I think this is a bug for codeigniter.

+4
source share
3 answers

This piece of code solved my problem. But for this I have to use assistants. At least I have a solution.

function value_field($field, $default='') { return (isset($_POST[$field])) ? $_POST[$field] : $default; } 
+4
source

You must set the validation rule in the field so that it can populate an invalid view. Fortunately, you can pass regular PHP functions, not just validation rules, to the set_rules() method so that you can just set the trim or something, and not the required one.

 $this->form_validation->set_rules('your_field', 'Your Label', 'trim'); 

This will populate the field and not make it mandatory.

+3
source

Using helper set set_value () works even for optional fields, I'm not sure where your problem lies ...

 echo form_input(array('name' => 'username', 'value' => set_value('username')); 
0
source

Source: https://habr.com/ru/post/1381830/


All Articles