Re: $_POST

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andrew Maxwell wrote:
When you submit something, and you want to make sure that the user
inputs all of the info, is there an easier way to do it than this:

if ((!$_POST[name]) || !$_POST[pass]) || (!$_POST[blah]))
{
etc.....
}

is there an easy way to check if all of the varibles have data in them?

Not sure if you will find this easier, but you can clean up your POST array (or any other array for that matter) and get rid of any entries matching some criteria you specify by using array_filter. In your case you probably want to get rid of any empty strings and anything just containing whitespace.


    function clean($arg) { return strlen(trim($arg)); }
    $fp = array_filter($_POST, 'clean');

Now you have your filtered post variables in the $fp array. You can quickly check if a certain array elements are set like this:

    if(isset($fp['name'],$fp['pass'],$fp['blah']))

-Rasmus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux