表格仍然返回真值,即使有空()

I'm having a problem for doing my form . When I click the button generate , I'm attempting to redirect to an error page but it stills redirect to the correct page even in the form it's empty.

if(isset($_POST['Generate'])) {
    if(!empty($_POST['aid'])) {
        $gen_link = "www.correctlink.com";
        $_SESSION['active'] = $aid;
        header("Location: http://$gen_link") ;
    } else {
        header("Location : http://error404.com");
    }
}   

Even when I click the generate button it stills redirect to www.correctlink.com I want the user to type something in the form

Form Code:

<input type="text" name="aid" id="aid" value="Enter Your Active Here" onfocus=" if (this.value == 'Enter Your Active Here') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter Your Active Here';}  "/><br /><br />

   <input type="submit" class="button" value="Generate" name="Generate" id="Generate"/>

The problem here is that you have set a default value of "Enter Your Active Here" in your textbox. If the user simply submits the form without even trying to enter anything in the textbox, the value of $_POST['aid'] becomes "Enter Your Active Here".

So what do you do? Simple, instead of checking for empty, check for

if($_POST['aid'] != "Enter Your Active Here" && ! empty(trim($_POST['aid'])))

Another solution would be to use a placeholder but since that's a HTML5 feature, the compatibility of that across browsers is limited.

EDIT: The second condition is added to make sure the code works in case javascript is disabled on the client machine and the user mischievously tries to submit form by emptying the textbox

If you have the value attribute set to something in the form, it will submit that as the value, therefore it won't be empty. Instead of checking if it's empty, check if it equals Enter Your Active Here. If you need a placeholder text, you could use the attribute placeholder instead of value.

The $_POST['aid'] is not empty because you set value for this as Enter Your Active Here

Use something like this

<input type="text" name="aid" id="aid" placeholder="Enter Your Active Here" .......

OR

<label>Enter Your Active Here</label><input type="text" name="aid" id="aid" .....

replace

 if(!empty($_POST['aid']))

by

if($_POST['aid']!="" && $_POST['aid']!="Enter Your Active Here")

Thanks.