Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeigniter form set value?

I must know..

is

$this->form_validation->set_value('first_name')

the same as

$this->input->post('first_name')

?

They both seem to get the input value. Is the first one more secure if I'm validating inputs?

like image 290
CyberJunkie Avatar asked May 25 '11 03:05

CyberJunkie


1 Answers

set_value() can return a default value if one is set in the second parameter, and will not return anything if the field was not validated with the Form Validation library, whereas $this->input->post() will return the $_POST value even if the field was not processed by the validation lib.

Both functions will return the modified value if "prep" rules have been run on the input.

When you want to read a post value, just use $this->input->post(), the set_value() type functions like set_select() and set_checkbox() will actually return something like selected="selected" rather than the actual input value, so this won't work for checkboxes, radios, and selects.

like image 80
Wesley Murch Avatar answered Oct 06 '22 00:10

Wesley Murch