Is it possible to get all post variables in ExpressionEngine, like you could in CodeIgniter?
Asked Answered
R

2

7

In a controller in CI you could get all post variables by doing something like this:

$data = $this->input->post();

In EE (built off of CI by the same people) the analogous syntax would be:

$data = $this->EE->input->post();

The only issue is that instead of an array with all of the data, you get a boolean of false.

Is there some way of getting an array of all post data, using ExpressionEngine rather than the POST superglobal?

Thanks.

Raine answered 20/6, 2012 at 21:7 Comment(3)
If you have the source code, read it from there. It was not mentioned in the documentation and I don't know where to get the source from.Monomania
Thanks. There was a solution that I just kind of winged: foreach($_POST as $key => $value){ $data[$key] = $this->EE->input->post($key); } This works fine, for anyone who finds value in this questionRaine
@Mike_K, post your solution as an answer and accept that answer.Generalissimo
R
9

Ok, the way to get results similar to CI within EE for all elements of a POST, while still leveraging the security features of EE is the following:

foreach($_POST as $key => $value){
     $data[$key] = $this->EE->input->post($key);
}

Since you can access POST vars by name, looping through them in $_POST, then explicitly calling each will yield the desired result.

Raine answered 21/6, 2012 at 16:15 Comment(0)
L
23

Try native

$this->input->post(NULL, TRUE); // returns all POST items with XSS filter 
$this->input->post(); // returns all POST items without XSS filter

Ref: https://www.codeigniter.com/user_guide/libraries/input.html

Leund answered 9/4, 2015 at 11:56 Comment(0)
R
9

Ok, the way to get results similar to CI within EE for all elements of a POST, while still leveraging the security features of EE is the following:

foreach($_POST as $key => $value){
     $data[$key] = $this->EE->input->post($key);
}

Since you can access POST vars by name, looping through them in $_POST, then explicitly calling each will yield the desired result.

Raine answered 21/6, 2012 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.