Validating form in php

07-Mar-2016 23:35

empty($_POST['arv_dt'])) { $dt = $_POST['arv_dt']; $array = explode("/",$dt); $day = $array[1]; $month = $array[0]; $year = $array[2]; if(!

checkdate($month, $day, $year)) { $msg2_dt = "Must be in m/d/y format"; } else { $today = strtotime("now"); if(strtotime($dt) if (isset($_POST['submit'])) { //checking for non-empty and non-negative integer if(empty($_POST['persons'])) $msg_persons = "You must supply number of persons travelling"; if(!

We are also going to implement some basic security feature like sanitization and validation of the user's input so that user can not insert potentially harmful data that compromise the website security or might break the application.

In this tutorial we will see how to use PHP to validate the data collected from a form.

You will see how to validate various fields used in general, like text, list, checkbox, radio button and we will also see how to retain POST data, so that after user submits form, even if the data supplied is not valid, data is not lost.

Live Demo Following is live demo of the PHP form we will create by the end of this tutorial.

The PHP filters provide an easy way to sanitize and validate the form data.

validating form in php-41

Jakarta online free sex

validating form in php-1

join dating sites

Validation for non-empty, alphabets and white space only Following code is added within the form if (isset($_POST['submit'])) { //checking name if(empty($_POST['full_name'])) $msg_name = "You must supply your name"; $name_subject = $_POST['full_name']; $name_pattern = '/^[a-z A-Z ]*$/'; preg_match($name_pattern, $name_subject, $name_matches); if(!

$name_matches[0]) $msg2_name = "Only alphabets and white space allowed"; } if (isset($_POST['submit'])) { //check email if(empty($_POST['email_addr'])) $msg_email = "You must supply your email"; $email_subject = $_POST['email_addr']; $email_pattern = '/^\w+([\.-]? \w+)*(\.\w{2,3})+$/'; preg_match($email_pattern, $email_subject, $email_matches); if(! $email_matches[0]) $msg2_email = "Must be of valid email format"; } if (isset($_POST['submit'])) { //date validation if(empty($_POST['arv_dt'])) $msg_dt = "You must supply an arival date"; if(!