Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP Form Validation

Name: <input type="text" name="name">
E-mail: <input type="text" name="email">
Website: <input type="text" name="website">
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
Comment

php validation form

<!DOCTYPE HTML>  
<html>
<head>
</head>
<body>  

<?php
// define variables and set to empty values
$name = $email = $gender = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = test_input($_POST["name"]);
  $email = test_input($_POST["email"]);
  $website = test_input($_POST["website"]);
  $gender = test_input($_POST["gender"]);
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

<h2>PHP Form Validation Example</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
  Name: <input type="text" name="name">
  <br><br>
  E-mail: <input type="text" name="email">
  <br><br>
  Website: <input type="text" name="website">
  <br><br>
  Gender:
  <input type="radio" name="gender" value="female">Female
  <input type="radio" name="gender" value="male">Male
  <input type="radio" name="gender" value="other">Other
  <br><br>
  <input type="submit" name="submit" value="Submit">  
</form>

<?php
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $gender;
?>

</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Php :: redirect to codeigniter 4 
Php :: laravel withValidator 
Php :: php ?? operator 
Php :: crypt password php 
Php :: laravel create command tutorial 
Php :: php string concatenation 
Php :: merge pdf php fpdf 
Php :: php ascii to decimal 
Php :: string operator in php 
Php :: how to redirect back to admin page if user is not authenticated in laravel based on the guard 
Php :: php get date from day of year 
Php :: laravel send data with a redirect 
Php :: laravel 8 login logout 
Php :: deleting a database in phpmyadmin 
Php :: php html text before first h2 tag 
Php :: laravel scheduler every 10 minutes 
Php :: PHP create array of specified size 
Php :: php how to concatenate strings 
Php :: yii2 rollback last migration 
Php :: slim disable display error details 
Php :: registerd navigations file uploadid 
Php :: check if product has crosssell woocommerce 
Php :: nginx phpmyadmin subdirectory 
Php :: how to select specific id in laravel using isset 
Php :: wordpress custom post type url not working 
Php :: livewire mount return type 
Php :: bring up the power shell console php 
Php :: no cache on browser back php 
Php :: PHP Number Shortener 
Php :: laravel validate form data unique array 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =