Posted inTechnology / Ajax / JavaScript / jQuery / Laravel / Mysql / Mysqli / php / Programming

Form validation client and server side using PHP

Form validation client and server side using PHP

In this Post We Will Explain About is Form validation client and server side using PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Differentiate between client side validation and server side validationExample

In this post we will show you Best way to implement Creating Client and Server-Side Form Validation, hear for Registration form with server And client side validationwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

In javascript simple client side validation we use JavaScript so It is a simple faster than Like as a PHP the server side validation but and manytimes when JavaScript simple disabled on browser data then JavaScript simple doesn’t work then any server side like as a validation will work.

create table user (id int primary key auto_increment,
name varchar(50),
useremail varchar(50),
gender varchar(1),
mobile varchar(10),
locations varchar(50))

File 1. connect.php :


File 2. register.js :

Used for client side validation.

function validate() {
    var liveform_db = document.getElementById("myformRegister");
    var err = "";
    var errDiv = document.getElementById("livemessage");
    var name = liveform_db.userName.value;
    if (name.trim() == "") {
        err = " * name is required. < br / > ";
    }

    var useremail = liveform_db.userEmail.value;
    var liveEmail = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    if (useremail.trim() == "") {
        err = err + " * useremail is required. < br / > ";
    } else if (!liveEmail.test(useremail)) {
        err = err + " * Invalid useremail < br / > ";
    }

    var password = liveform_db.userPassword.value;
    if (password.trim() == "") {
        err = err + " * Password required. < br / > ";
    } else if (password.length < 4) {
        err = err + "*Password required be minimun 4 characters.
"; } var confPassword = liveform_db.userConfPassword.value; if (confPassword != password) { err = err + "*Password and confirm password required be same.
"; } var mobile = liveform_db.userPhone.value; var latestPhone = /^\d*$/; if (mobile != "" && !latestPhone.test(mobile)) { err = err + "*Phone required be in integer.
"; } if (err.trim() != "") { errDiv.innerHTML = err; return false; } else { return true; } }

File 3. registration.php :

Used for simple server side Like as a PHP validation and save the Databased record in table.

()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/";
if(trim($name) == "") {
$livemessage = "*name is required.
"; } if(trim($useremail) == "") { $livemessage = $livemessage."*useremail is required.
"; } else if(!preg_match($liveEmail,$useremail)) { $livemessage = $livemessage."*Invalid useremail
"; } if(trim($password) == "") { $livemessage = $livemessage."*Password required.
"; } else if(strlen($password) < 4) { $livemessage = $livemessage."*Password required be minimun 4 characters.
"; } if($confPassword != $password) { $livemessage = $livemessage."*Password and confirm password required be same.
"; } $latestPhone = "/^\d*$/"; if(!preg_match($latestPhone, $mobile)) { $livemessage = $livemessage."*Phone required be in integer.
"; } if($livemessage == ""){ $query = "insert into user (name,useremail,gender,mobile,locations) values ('$name','$useremail','$gender','$mobile','$locations')"; if(mysql_query($query)){ echo "Live Record Saved!"; } else { echo "Live Unable to Save!"; } } } ?> Pakainfo.com Registration
Name* " name="userName" id="userName" />
Email* " name="userEmail" id="userEmail" />
USER Password*
USER Confirm Password*
USER Gender name="userGender" value="m" id="rdMale"/> Male name="userGender" value="f" id="rdFemale"/> Female
USER Phone " name="userPhone" id="userPhone">
USER Address

Example

I hope you have Got What is How to Validate Form with PHP – Server Side Validation And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype