tags:

views:

62

answers:

5

I've done a few searches and not come up with anything, I'm sure it's obvious.

Basically I'm trying to work out if anything has been passed via GET from a form.

I know how to check for individual elements, but I just want to do a quick check if anything at all is passed

Cheers

+3  A: 

This should do the job:

if (!empty($_GET))
{
}
therefromhere
+1  A: 
if ( count($_GET) > 0 ) echo("I hear you!");
mvds
+1  A: 

if(empty($_GET)) { /* no parameters passed*/}

Mchl
+1  A: 

just check the length of the $_GET array via count($_GET). if none ha passed it should be 0

Gilad
+2  A: 

Be careful when using count($_GET). If you submit the form with empty values it will still create keys for the fields, and your count() will be greater than 0 and empty($_GET) will be false.

<?php 
print_r($_GET);
?>

<form action="" method="get">
    <input type="text" name="name">
    <textarea name="mytext"></textarea>
    <input type="submit">
</form>

Make sure the fields are actually not empty:

function ne($v) {
    return $v != '';
}

echo count($_GET);                     // prints 2
echo count(array_filter($_GET, 'ne')); // prints 0
Aillyn
Thanks for all your help
grant