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.

Colin Brock
  • 21,267
  • 9
  • 46
  • 61
Mike_K
  • 9,010
  • 5
  • 20
  • 27
  • 1
    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. – Esailija Jun 20 '12 at 21:20
  • 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 question – Mike_K Jun 20 '12 at 22:20
  • @Mike_K, post your solution as an answer and accept that answer. – Kinjal Dixit Jun 21 '12 at 12:18

2 Answers2

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

Stack Programmer
  • 679
  • 6
  • 18
Shahjahan Jewel
  • 2,301
  • 24
  • 23
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.

Mike_K
  • 9,010
  • 5
  • 20
  • 27