Reply to Re: [PHP] $_POST

Your name:

Reply:


Posted by Rasmus Lerdorf on 01/17/05 11:13

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация