Reputation: 1852
I am newbie and I am trying to simple form submission with validation (not tidy validation).
My PHP code is here:
<html>
<head></head>
<title>Form Handling</title>
<body>
<h1>Contact Form</h1>
<form name="form1" action="contact_val.php" method="POST">
Name <input type="text" name="fname"><br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$fname = $_POST['fname'];
if (!isset($fname) or empty($fname)){
echo "Please enter name!";
}
}
?>
I just want to know how to redirect on this page again if input is blank and submit button clicked otherwise go to action page.
Upvotes: 2
Views: 60
Reputation: 21
You can seperate the this File into two file. html based content with ".html", php tag contetn with ".php", then write php file.
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$fname = $_POST['fname'];
if (!isset($fname) or empty($fname)){
echo "Please enter name!";
}
header("location: (html page url)");
}
?>
Write this code
Upvotes: 1