Php form validation

preview_player
Показать описание
In this video, we will be explaining in detail on how to validate a HTML form with PHP ( Php form validation ) in a more advanced and a more secured way.

Stay tuned follow up with me !!

Php form validation ( php form validation ) ( php form validation code )
simple php form validation. form validation in php. php security. server side form validation. php form handling and validation

---------------------------- PHP ---------------------
GET vs POST
Both GET and POST create an array (e.g. array( name1 = value1, name2 = value2, name3 = value3, ...)). This array holds name/value, where name are the names of the form controls and values are the input data from the user. But POST will parse the data without showing it in the URL. GET will parse the data showing it in the url.
While processing passwords, it is advisable to use POST method, so that no one can see it in the url.

PHP FUNCTION
preg_match() is used to find match of a pattern in a string;

Subscribe to this channel

( Php form validation ) #phpformvalidation #phpformvalidate #phpforbeginners

php form validation and form handling example in php
php form validation tutorial 2021
Рекомендации по теме
Комментарии
Автор



<?php
// isset($_POST['submitForm']) here is working like, if the submitForm button is been clicked, then if it returns true.. It will continue what is in the IF statement

$fullName = $_POST['fullName']; // Full name input data
$userName = $_POST['userName']; // User name input data
$email = $_POST['email']; // Email address input data
$password_1 = $_POST['password_1']; // First password input data
$password_2 = $_POST['password_2']; // Second password input data

// Error checks // This functions will invoke (call upon) the function outside, so far their names and argument are the same

// Check if any of the submitted data from the form is empty
emptyInputs($fullName, $userName, $email, $password_1, $password_2);

// Invalid inputs
// Check if any of the submitted data from the form is not valid.. Check the full name if has special characters, it will check if the username has some special characters aside from text and number, it will also check if the provided email address is a valid email address and also check if the password match with password lesser than eight
invalidInputs($fullName, $userName, $email, $password_1, $password_2);

} else {
// If the submitForm is not been clicked, it will echo this "No" value
echo "No";
}

// Empty input checks
function emptyInputs($fullName, $userName, $email, $password_1, $password_2){
if(empty($fullName) || empty($userName) || empty($email) || empty($password_1) || empty($password_2)){
header("Location:
exit();
}
}

function invalidInputs($fullName, $userName, $email, $password_1, $password_2){
// Check the full name if has special characters
if(!preg_match("/^[a-zA-Z ]*$/", $fullName)){
header("Location:
exit(); // The exit() will stop the script from any futher running or execution
}

// Check if the full name has special characters and strings that are not in the []
if(!preg_match("/^[a-zA-Z0-9]*$/", $userName)){
header("Location:
exit();
}

if(!filter_var($email, FILTER_SANITIZE_EMAIL) || !filter_var($email, FILTER_VALIDATE_EMAIL)){
header("Location:
exit();
}

// Check if the first password and the second password doesn't match
if($password_1 !== $password_2){
header("Location:
exit();
}

// Check if the password is lesser than eight
if(strlen($password_1) < 8){
header("Location:
exit();
}
}

hcodehub
Автор

to check for existence of email and username in database

oluwaseunolukayode