OK to simplify things, I have created 1 form, with 1 text field and 1 submit button.
What I am trying to do is that the field should be filled. If it is not, then an error displays telling the user that he has to fill it.
So here is the code I have so far. What I also did is this:
When the user goes to that link, he will be shown 1 form. If the form contains errors (the form has been submitted but without any text in the field), he will be shown another form (same form, but with the error displayed). So here it is:
<body>
<?php
$form_is_bad = "0";
if(isset($_POST["submit"])){
$form_error = "<font color=\"red\"><br>The following errors occured. Please make the necessary changes and resubmit the form.</font><br><br>";
if(!isset($_POST["name"]) || ($_POST["name"] == "")){ $form_is_bad = "1"; $form_error .= "<strong><font color=\"red\">»</font></strong> <font color=\"#5175A8\">Please enter a valid text.</font><br>"; }
if($form_is_bad == "1"){
?>
<form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>">
<div align="left" style="margin-top:15px; margin-bottom:40px;"><?php echo $form_error; ?></div>
<p>
<input type="text" name="name" value="<?php echo $_POST["name"]; ?>">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<?php
}
else{
header("Location: [url]http://www.findagoodhost.com/thankyou.html[/url]");
}
}
else{
?>
<form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>">
<div align="left" style="margin-top:15px; margin-bottom:40px;"><?php echo $form_error; ?></div>
<p>
<input type="text" name="name" value="<?php echo $_POST["name"]; ?>">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<?php
}
?>
</body>
The problem I am having is that the form does not get checked, and submits it whether or not the field has been filled. And it does not redirect me to the thank you page.
Any help would greatly be appreciated.
Thank you