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 :: laravel app service provider why eloquent model error 
Php :: Laravel docker-compose 404 not found Nginx 
Php :: how to pass javascript variable to php 
Php :: int to string in php 
Php :: how to check request method in php 
Php :: laravel showing index of 
Php :: php artisan spark not working in codeigniter 
Php :: laravel store mail driver info in database 
Php :: breaking long array in php 
Php :: SymfonyComponentHttpKernelExceptionNotFoundHttpException: POST http://localhost/post 
Php :: wordpress register_post_type capability gutenberg 
Php :: folder name escape php 
Php :: what does the initals of php stand for? 
Php :: laravel collect whereNotIn not working 
Php :: laravel child relation get max value 
Php :: how to store api response to avariable in phpp 
Php :: the_fiel 
Php :: moodle admin cli 
Php :: Extract all audio tracks / streams 
Php :: dql if or ifnull 
Php :: laravel framework 
Php :: how to hide .php in url 
Php :: Select specefied columns from all data in laravel 
Php :: install phpmyadmin debian 11 
Php :: add taxonomy to custom post type 
Php :: phpstorm deployment 
Java :: minecraft death counter 
Java :: android glide dependency 
Java :: priority queue reverse order java 
Java :: spigot title 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =