CodeIgniter Forums
Array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Array (/thread-8721.html)



Array - El Forum - 05-28-2008

[eluser]ealonw[/eluser]
How can I turn post variables into an array?

$this->input->post('fname');
$arg['fname'] = ?
$this->input->post('lname');
$arg['lname'] = ?
$this->input->post('email');
$arg['email'] = ?

am i doing this right?


Array - El Forum - 05-28-2008

[eluser]onejaguar[/eluser]
If you aren't using xss_clean() you can just use the $_POST array.

If you are using xss_clean() you can set
Code:
$config['global_xss_filtering'] = TRUE;
In application/config/config.php and it will run xss_clean() on everything in the $_POST array, or you can do a one off:
Code:
$_POST['email'] = $this->input->xss_clean($_POST['email')



Array - El Forum - 05-28-2008

[eluser]ealonw[/eluser]
would i be able to do something like this in CI..?

$fname = $this->input->post(’fname’);
$arg[’fname’] = $fname;
$lname = $this->input->post(’lname’);
$arg[’lname’] = $lname;
$email = $this->input->post(’email’);
$arg[’email’] = $email;

and then do

foreach($arg as $key=>$value)...

It seems the $arg[''] = $whatever;
doesnt work at all... why?


Array - El Forum - 05-28-2008

[eluser]Jamie Rumbelow[/eluser]
If you want to loop through, just use this:

Code:
foreach ($_POST as $key => $value) {

$arg[$key] = $value;

}

Remember - the $_POST array functions just as a regular array does.