Welcome Guest, Not a member yet? Register   Sign In
pass input->post to model
#1

[eluser]Jagar[/eluser]
Hello everyone,

I'm trying to pass the $this->input->post() to my model functions, but when doing print_r it doesn't return anything.

I know I can do $this->modelname->functionmame($_POST), but using input is safer.

Thanks all!
#2

[eluser]Dam1an[/eluser]
Using the input class is only safer if you have either global xss clean or in the actual request

Is there any reason why you can't just call the post variables using the input class in the model, or do you want to pass it as an array as it may accept a non post array?
#3

[eluser]Jagar[/eluser]
I'm building a search form for this project I'm working on.

I have a drop down box where the user selects the type of search, depending on the selection they make, a different form is displayed, with different fields, so once they click on search, in my controller I find the type of search they want to form, and trying pass the post to the model to different function, whether the model functions will use it or not, it's up to the model.

If there's no way then i will do the following, which may be equivalent
Code:
$this->input->xss_clean($_POST);
#4

[eluser]Jondolar[/eluser]
$this->input->post() does not return an array, it returns the value of the posted field that is passed to it so you can't do a print_r() with it's return value.

$this->input->post('something'); The value of the form field "something" would be returned.
#5

[eluser]Jagar[/eluser]
Yes that's what I thought, I'm using the specified code using $_POST to do what I want.

Thanks for your responses
#6

[eluser]Colin Williams[/eluser]
Code:
$this->input->xss_clean($_POST);

This is fine. I typically just throw $_POST at my model functions when dealing with user input. $_POST is not always evil. Just sanitize it. You can also use global XSS filtering or use the shorthand xss_clean() function.




Theme © iAndrew 2016 - Forum software by © MyBB