Welcome Guest, Not a member yet? Register   Sign In
Avoiding something with $_POST
#6

[eluser]BrianDHall[/eluser]
[quote author="Ci beginner" date="1248935582"]Hey there!

Just a simple question... with PHP, I used to write:

Code:
if (!$_POST) ...

But now, using the $this->input->post('blabla'); and stuff... how can I make the same thing in CI? I mean, if the user didn't posted anything, do X.

Thank you![/quote]

Tons of options, none of them more right than another.

The only one thing is technically...the way you were doing it wasn't strictly 'right', as if nothing was posted $_POST would be an unitialized variable and would generate a PHP Notice.

A few options:

Code:
if (! is_set($_POST) )
if ( empty($_POST) )
if (! $this->input->post('necessary_form_field') ) <- my preference
if ($_SERVER['REQUEST_METHOD'] != "POST")

The Input class of CodeIgniter is purely to allow extra helper and convenience functions and provide some automatic security functioning so you don't have to do so much data sanitizing.

There is nothing, however, unsafe about just checking to set if something was POSTed by accessing the $_POST superglobal directly.

No reason to change what you are doing (other than not accessing an uninitialized variable), and there isn't much of a real advantage to using a CI built-in method.


Messages In This Thread
Avoiding something with $_POST - by El Forum - 07-29-2009, 07:33 PM
Avoiding something with $_POST - by El Forum - 07-29-2009, 08:03 PM
Avoiding something with $_POST - by El Forum - 07-29-2009, 09:20 PM
Avoiding something with $_POST - by El Forum - 07-29-2009, 11:10 PM
Avoiding something with $_POST - by El Forum - 10-05-2009, 09:24 PM
Avoiding something with $_POST - by El Forum - 10-05-2009, 09:41 PM
Avoiding something with $_POST - by El Forum - 10-06-2009, 06:40 AM
Avoiding something with $_POST - by El Forum - 10-06-2009, 09:42 AM
Avoiding something with $_POST - by El Forum - 10-06-2009, 11:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB