Reputation: 22674
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
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
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
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
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