CyberJunkie
CyberJunkie

Reputation: 22674

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?

Upvotes: 5

Views: 20148

Answers (4)

Harsh
Harsh

Reputation: 2096

With the previous validation library thevalidation->first_name and input->post(‘first_name’) were interchangeable but the new library doesn’t alters the post values anymore.

Upvotes: 2

No Results Found
No Results Found

Reputation: 102745

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.

Upvotes: 7

Sean Walsh
Sean Walsh

Reputation: 8344

set_value() is used to re-populate a form once it has failed validation. There is no additional filtering on it, so you should use $this->input->post() if you have no need to pass the value back to the form.

Upvotes: 4

onteria_
onteria_

Reputation: 70497

I think you're referring to this:

<input type="text" name="quantity" value="<?php echo set_value('quantity', '0'); ?>" size="50" />

Which in this case set_value is just repopulating the field on validation error. This:

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

Is just getting the $_POST value of first_name.

Upvotes: 3

Related Questions