Form Validation In PHP

Simple html from
<?php
if ( ! empty( $_POST[‘guess’] ) )
{
print “last guess: “.$_POST[‘guess’];
}
?>
Type your guess here:
Program for Form action Using POST

People

Title:

Full name:

Memo:

<?php $ title=$_POST[‘ title’];

$fullname=$_POST[‘fullname’];

$memo=$_POST[‘memo’];

if(isset($_POST[‘sub’]))

{

echo “title=$title”;

echo “fullname=$fullname”;

echo “memo=$memo”; }

?>

Program To Check Weather Form Fields Empty Or Not

Information

Nickname:
Title:
First Name:
Middle Name:
Last Name:
Primary Email:
Secondary Email:

          

<?php
$errors=0;
if(isset($_POST[‘sub’]))
{
$nickname=$_POST[‘nickname’];
$firstname=$_POST[‘firstname’];
$lastname=$_POST[‘lastname’];
$email=$_POST[’email’];
if (!trim($nickname)) {
echo ”
Nickname is required.”;
$errors++;
}
if (!trim($firstname)) {
echo ”
First name is required.”;
$errors++;
}
if (!trim($lastname)) {
echo ”
Last name is required.”;
$errors++;
}
if (!trim($email)) {
echo ”
Primary email address is required.”;
$errors++;
}
}
?>

Form Validation Function for mobile number
<?php
function mobile_number($data, $desc)
{
$regex = “/^\([2-9][0-9]{2}\)[2-9][0-9]{2}-[0-9]{4}/i”;
if(preg_match($regex, $data) != 1)
{
return “The ‘$desc’ field isn’t valid!”;
}
return true;
}
?>
Validation for single checkbox
<?php
$value = ‘yes';
echo “ Subscribe?”;
if (isset($_POST[‘subscribe’])) {
if ($_POST[‘subscribe’] == $value) {
$subscribed = true;
} else {
$subscribed = false;
print ‘Invalid checkbox value submitted.';
}
} else {
$subscribed = false;
}
if ($subscribed) {
print ‘You are subscribed.';
} else {
print ‘You are not subscribed';
}
?>
Get Values of Multiple Checked Check boxes in Form
Get Values of Multiple Checked Checkboxes

PHP: Get Values of Multiple Checked Checkboxes

<?php
if(isset($_POST[‘submit’]))
{
if(!empty($_POST[‘check_list’]))
{
$checked_count = count($_POST[‘check_list’]);
echo “You have selected following “.$checked_count.” option(s):
“;
foreach($_POST[‘check_list’] as $selected)
{
echo ”

“.$selected .”

“;
}
echo ”
Note : You Can Select  Another Company “;
}
else
{
echo “Please Select Atleast One Option.“;
}
}
?>

Program for Form submitting
Name: Email Address:

<?php
if (isset($_POST[‘submit’]))
{
echo “Hi “.$_POST[‘name’].”!
“;
echo “hello “.$_POST[’email’].” “;
}
?>

Leave a Reply

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