pkrishna42
10-19-2017, 02:12 PM
i want to add pregmatch field for phone email and website for this validation.
<?php
function _ent($val)
{
return htmlentities($val);
}
function _element($arr,$index)
{
return isset($arr[$index]) ? $arr[$index] : '';
}
$errors = [];
$data = [];
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$data = array_map('trim',$_POST);
if($data['Phone'] == '')
{
$errors['Phone'] = " Phone is required.";
}
if($data['Email'] == '')
{
$errors['Email'] = " Email is required.";
}
if($data['Web'] == '')
{
$errors['Web'] = " Company Website is required.";
}
if(empty($errors))
{
header('location:ok.php');
die;
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<table width="1200" border="1">
<tbody>
<form action="#" method="post">
<tr>
<td><input type="text" name="Phone" placeholder=" Enter Phone Number" style="height:45px; width:270px; margin-right: 20px; margin-bottom:20px; " value="<?= _ent(_element($data,'Phone')); ?>"> <?= _element($errors,'Phone'); ?></td>
</tr>
<tr>
<td><input type="text" name="Email" placeholder=" Enter Your Email" style="height:45px; width:270px; margin-right: 20px; margin-bottom:20px; " value="<?= _ent(_element($data,'Email')); ?>"> <?= _element($errors,'Email'); ?></td>
</tr>
<tr>
<td><input type="text" name="Web" placeholder=" Enter Company Website" style="height:45px; width:270px; margin-right: 20px; margin-bottom:20px; " value="<?= _ent(_element($data,'Web')); ?>"> <?= _element($errors,'Web'); ?></td>
</tr>
<tr><td><input type="submit" name="submit" value="submit"> </td></tr>
</tbody>
</form>
</table>
</body>
</html>
<?php
function _ent($val)
{
return htmlentities($val);
}
function _element($arr,$index)
{
return isset($arr[$index]) ? $arr[$index] : '';
}
$errors = [];
$data = [];
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$data = array_map('trim',$_POST);
if($data['Phone'] == '')
{
$errors['Phone'] = " Phone is required.";
}
if($data['Email'] == '')
{
$errors['Email'] = " Email is required.";
}
if($data['Web'] == '')
{
$errors['Web'] = " Company Website is required.";
}
if(empty($errors))
{
header('location:ok.php');
die;
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<table width="1200" border="1">
<tbody>
<form action="#" method="post">
<tr>
<td><input type="text" name="Phone" placeholder=" Enter Phone Number" style="height:45px; width:270px; margin-right: 20px; margin-bottom:20px; " value="<?= _ent(_element($data,'Phone')); ?>"> <?= _element($errors,'Phone'); ?></td>
</tr>
<tr>
<td><input type="text" name="Email" placeholder=" Enter Your Email" style="height:45px; width:270px; margin-right: 20px; margin-bottom:20px; " value="<?= _ent(_element($data,'Email')); ?>"> <?= _element($errors,'Email'); ?></td>
</tr>
<tr>
<td><input type="text" name="Web" placeholder=" Enter Company Website" style="height:45px; width:270px; margin-right: 20px; margin-bottom:20px; " value="<?= _ent(_element($data,'Web')); ?>"> <?= _element($errors,'Web'); ?></td>
</tr>
<tr><td><input type="submit" name="submit" value="submit"> </td></tr>
</tbody>
</form>
</table>
</body>
</html>