hi..
This is form validation code..im getting errors..
1.I have to check whether all the field r empty and for certificates,photo,biodata field shud be validated for type,size,whether field is empty..
2.how to validate the datepicker i used javascript
<?php
session_start();
if(isset($_POST['Role'],$_POST['Name'],$_POST['datepicker'],$_POST['gender'],$_POST['activity'],$_POST['Address'],$_POST['Photo'],$_POST['Biodata']$_POST['certificates'],$_POST['Salary']))
{
$errors=array();
$Emp_Save=$_POST['Emp_Save'];
$Emp_Cancel=$_POST['Emp_Cancel'];
$Role=$_POST['Role'];
$Name=$_POST['Name'];
$datepicker=$_POST['datepicker'];
$gender=$_POST['gender'];
$activity=$_POST['activity'];
$Address=$_POST['Address'];
$Photo=$_POST['Photo'];
$Biodata=$_POST['Biodata'];
$certificates=$_POST['certificates'];
$Salary=$_POST['Salary'];
if($_POST['Emp_Save'])
{
$sql="INSERT INTO `formdetails` (role,name,,date_of_birth,gender,activity,address,photo,biodata,certificates,salary) VALUES ('$Role', '$Name','$datepicker',, '$gender','$activity','$Address','$Photo','$Biodata','$certificates','$_EmpSalary')";
$result=mysql_query($sql) or die(mysql_error());
}
else
// check for data in required fields
if($Role == ""){
$errors[]='Please Select The Employee Role!';
}
if(strlen($Name >30){
$errors[]='Name Is Too Long!';
}
else if(empty($Name))
{
$errors[]='Please Fill The Field!';
}
//this to validate date of birth
if($datepicker == ""){
$errors[]='Please Select The Date!';
}
if($gender == ""){
$errors[]='Please Select The Gender!';
}
//activity radio button is used
if($Activity == ""){
$errors[]='Please Select the Status!';
}
if($Address == ""){
$errors[]='Please Enter The Address!';
}
if(array_key_exists('Photo', $_FILES)) {
$allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg');
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
// Validate the uploaded file
if($_FILES['Photo']['size'] === 0
|| empty($_FILES['Photo']['tmp_name'])) {
echo("No file was selected.
\r\n");
} else if($_FILES['Photo']['size'] > 50000) {
echo("The file was too large.
\r\n");
} else if($_FILES['Photo']['error'] !== UPLOAD_ERR_OK) {
// There was a PHP error
echo("There was an error uploading.
\r\n");
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
}
if(array_key_exists('Biodata', $_FILES)) {
$allowed_filetypes = array('.pdf');
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
// Validate the uploaded file
if($_FILES['Biodata']['size'] === 0
|| empty($_FILES['Biodata']['tmp_name'])) {
echo("No file was selected.
\r\n");
} else if($_FILES['Biodata']['size'] > 50000) {
echo("The file was too large.
\r\n");
} else if($_FILES['Biodata']['error'] !== UPLOAD_ERR_OK) {
// There was a PHP error
echo("There was an error uploading.
\r\n");
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
}
if(array_key_exists('certificates', $_FILES)) {
$allowed_filetypes = array('.pdf');
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
// Validate the uploaded file
if($_FILES['certificates']['size'] === 0
|| empty($_FILES['certificates']['tmp_name'])) {
echo("No file was selected.
\r\n");
} else if($_FILES['certificates']['size'] > 50000) {
echo("The file was too large.
\r\n");
} else if($_FILES['certificates']['error'] !== UPLOAD_ERR_OK) {
// There was a PHP error
echo("There was an error uploading.
\r\n");
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
}
if($Salary == ""){
$errors[]='Please Enter The Salary!';
}
}
}
?>