Let's say I have a simple form as follows that has only a text field and a submit button.

<form id="dataForm" name="dataForm" method="post">      

  <?php
    if(isset($_POST['btnSubmit']))
    {
        if(isset($_POST['txtName'])&&!is_null($_POST['txtName'])&&$_POST['txtName']!="")    
        {
            header("location:Home.php");    
        }
        else
        {
            echo "<font style='color:red'>Name is mandatory.</font>";   
        }
    }
 ?>

    <input type="text" id="txtName" name="txtName" /><br/>
    <input type="submit" value="Submit" id="btnSubmit" name="btnSubmit" />        
</form>

The page is redirected to Home.php, if some text is inputted in the given textfield txtName and the submit button is clicked. An error message is displayed, if the text field is left blank and the submit button is clicked.

But I don't want to redirect the page using header("lcation:Home.php"); (I don't want to use the GET method at all in this case. The method must be POST anyway). I just want to redirect using the form's action attribute but only after checking the (server-side) validation to see, if the text field is left blank. It should only be redirected, if it fulfills the given server-side validation. Is this possible?

<form id="dataForm" name="dataForm" method="post" action="Home.php">

    <input type="text" id="txtName" name="txtName" /><br/>
    <input type="submit" value="Submit" id="btnSubmit" name="btnSubmit" />        

</form>
0

There are 0 best solutions below