Hello दोस्तों! आज मैं आपको इस पोस्ट में PHP Validation Form and Registration form in php का पूरा Program …. बताऊंगा,
शुरू करने से पहले जान लेते हैं कि what is Validation in PHP…?
Validation:
“Validation का अर्थ है User द्वारा submitted input की जांच करना.”
PHP में दो प्रकार के Validation होते हैं वह कुछ इस प्रकार हैं..
1. Client – side Validation –
Validation client machine web browser पर कार्य करती है.
2. Server – side Validation –
Submitted data को server तक भेजा जाता है और serve machine में validation perform करता है.
तथा उसकी जांच करता है.
Example of PHP Validation Form :-
<!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style></head> <body> <?php //define variables and set to empty values $nameErr = $emailErr = $ganderErr = $websiteErr = " "; $name = $email = $gender = $website = " "; if ($_SERVER["REQUSET_METHOD"]= "POST"){ if (empty($_POST["name"])){ $nameErr ="Name is required"; } else{ $name = test_input($_POST["name"]); //check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z-' ]*$/",$name)){ $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])){ $emailErr ="Email is required"; } else{ $email = test_input($_POST["email"]); //check if email adderss is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)){ $emailErr = "Invalid email format"; } } if (empty($_POST["website"])){ $website = " "; } else{ $website = test_input($_POST["website"]); //check if URL address syntax is valid if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%?=~_|]/i",$website)){ $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])){ $comment = ""; } else{ $comment = test_input($_POST["comment"]); } if (empty($_POST["gender"])){ $genderErr = "Gender is required"; } else{ $gender = test_input($_POST["gender"]); } } function test_input($data){ $data = trim($data); $data = stringlashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>PHP Form Validation Example</h2> <p><span class="error">* required field</span></p> <form method="post" action=">?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> Name: <input type="text" name="name"> <span class="error">* <?php echo $nameErr;?></span><br><br> E-mail: <input type="text" name"email"> <span class="error">* <?php echo $emailErr;?></span><br><br> Website: <input type="text" name"website"> <span class="error">* <?php echo $websiteErr;?></span><br><br> Comment: <textarea name"comment" rows="5" cols="40"></textarea><br><br> Gender: <input type="radio" name="gender" value="male">Male <input type="radio" name="gender" value="female">Female <input type="radio" name="gender" value="other">Other <span class="error">*<?php echo $ganderErr;?></span> <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 $comment; echo "<br>"; echo $gender; ?> </body> </html>
Note:- ये पोस्ट आपको कैसी लगी आप कमेंट कर के बताईये !अगर आपको कुछ पूछना या अपनी राय देनी हो तो आप हमे कमेंट या [email protected] ईमेल करके बता सकते है हम पूरी कोसिस करेंगे की आपका रिप्लाई जल्दी से जल्दी दे सखे ….
इसे भी देखे:
Hello दोस्तों! नीचे दिए गए links पर click करके आपको हम इस पोस्ट में (Computer Online Test) की Practice कराएंगे जिससे आप अपने CCC, O level , कम्प्युटर GK की practice कर सकते है.
इस post के द्वारा आप अपनी कम्प्युटर की नॉलेज बड़ सकते है.
उसके साथ ही साथ आप अपने कई प्रकार के पेपरो की भी तैयरी भी कर सकते है.
जैसे की CCC, O level , कम्प्युटर GK की practice कर सकते है,