saftutorials.com
PHP Form URL/EMAIL

Form URL/EMAIL should validate that user enters proper format URL/EMAIL. The easiest way to validate the URL/EMAIL by using below function.


We can check each $_POST variable with the validate_input() function, and the script looks like this:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = validate_input($_POST["email"]);
$url = validate_input($_POST["url"]);
}
function validate_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>


trim() function

Removes whitespace and other predefined characters from both sides of a string


stripslashes() function

Removes backslashes added. This function can be used to clean up data retrieved from an HTML form.


htmlspecialchars() function

convert the predefined charecters like < (less than), > (greater than) etc. in to HTML entities


Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic