Hi,

I have a problem with form submission.

Situation
I have 3 .php files.
one.php -> Main file to run. If textbox filled with data then it is redirected to three.php.
two.php -> This file is to refer a friend. If email textbox is filled with data then it is redirected to three.php. It is included in the one.php.
three.php -> Result page. Either Submission from one.php or two.php redirect to this page on successful submission.

Problem
one.php -> On clicking the submit button without properly checking the php and javascript validation the page is redirected to three.php.
two.php -> On clicking the submit button without checking the php validation the page is redirected to three.php.

Code: one.php
PHP Code:
<?php

if(isset($_POST["t"]))
{
    
header("Location: three.php");
}

?>

<html>
<head>
<title>Test Script</title>
<script language="javascript">
function validate(thisform)
{
      if(document.f.t.value=="")
      {
            alert("Please enter name");
            document.f.t.focus();
            return false;
      }
}
</script>
</head>
<body>
<form name="f" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>" onsubmit="return validate(this)">
Name<input type="text" name="t" size="20"><br>
<input type="submit" name="b" value="Submit">
</form>
</body>
</html>

<?php

include("two.php");

?>
Code: two.php
PHP Code:
<?php

if(isset($_POST["email"]))
{
    
$email $_POST["email"];
    
mail($email"Test""Test Mail""From: sender <[email protected]>");
    
header("Location: three.php");
}

?>

<form name="f" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<table border="0">
    <tr>
        <td>
            Write Email ID Here <input type="text" name="email" size="20">
        </td>
        <td>
            <input type="submit" name="b" value="Submit">
        </td>
    </tr>
</table>
</form>
Code: three.php
PHP Code:
<?php

echo "Mail Sent Successfully";

?>
I need your assistance to understand the problem and help to solve the situation. Thank you so much.