This is a discussion on Detecting if post data empty??? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello, I'm having a problem detecting if post data is empty. I've got a search form on one ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello,
I'm having a problem detecting if post data is empty. I've got a search form on one page, that posts to a form on another page. If the user doesn't enter anything, then I wanted to make the variable equal a dot. But for some reason, even if you leave the form input blank and just hit submit, the post variable is not detected as empty using either isset($var) or empty($var). Neither of these work and the form page that gathers the post data assumes that the variable holds some value. What would that value be? How else can I detect if the nothing has been entered on the search form? Thanks |
|
|||
|
"Marv" <marv@mister.com> wrote:
> Hello, > > I'm having a problem detecting if post data is empty. > > I've got a search form on one page, that posts to a form on another > page. If the user doesn't enter anything, then I wanted to make the > variable equal a dot. But for some reason, even if you leave the form > input blank and just hit submit, the post variable is not detected as > empty using either isset($var) or empty($var). Neither of these work > and the form page that gathers the post data assumes that the variable > holds some value. > > What would that value be? How else can I detect if the nothing has > been entered on the search form? > > Thanks Something like if (trim($_POST['fieldname'])!='') { // whatever ... } Because yes, you're right. When the HTML form is created, the input values by default are all empty strings. And when posted, all of these end up in the $_POST array. -- bonfils http://kim.bonfils.com |