function form_example_form($form, &$form_state) {
$form['empcode'] = array(
'#weight' => '0',
'#required' => '1',
'#type' => 'textfield',
'#title' => t('Employee Code'),
);
$form['empname'] = array(
'#weight' => '1',
'#required' => '1',
'#type' => 'textfield',
'#title' => t('Employee Name'),
);
$form['empemail'] = array(
'#weight' => '2',
'#required' => '0',
'#type' => 'textfield',
'#title' => t('Employee Email'),
);
$form['empdesignation'] = array(
'#weight' => '3',
'#required' => '1',
'#type' => 'textfield',
'#title' => t('Employee Designation'),
);
$form['mobile'] = array(
'#weight' => '4',
'#required' => '0',
'#type' => 'textfield',
'#title' => t('Mobile No.'),
);
$form['ipphone'] = array(
'#weight' => '5',
'#required' => '0',
'#type' => 'textfield',
'#title' => t('IP Phone'),
);
$form['qualifications'] = array(
'#weight' => '6',
'#required' => '0',
'#type' => 'textfield',
'#title' => t('Qualifications'),
);
$form['profile'] = array(
'#weight' => '7',
'#required' => '0',
'#type' => 'textarea',
'#title' => t('Profile'),
);
$form['file'] = array(
'#weight' => '8',
'#type' => 'file',
'#size' => '30',
'#title' => t('Employee Photo'),
);
$form['captcha'] = array(
'#weight' => '9',
'#type' => 'captcha',
'#captcha_type' => 'captcha/Math',
);
$form['submit'] = array(
'#weight' => '10',
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function form_example_form_validate($form, &$form_state) {
/*if (!($form_state['values']['price'] > 0)){
form_set_error('price', t('Price must be a positive number.'));
}*/
// print('<pre>'.print_r($form_state['values'],1).'</pre>');
//die();
$file = file_save_upload('file', array(
'file_validate_is_image' => array(),
'file_validate_extensions' => array('png gif jpg jpeg'),
));
if ($file) {
if ($file = file_move($file, 'public://')) {
$form_state['values']['file'] = $file;
}
else {
form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
}
}
else {
form_set_error('file', t('No file was uploaded.'));
}
}
i want to add advance level validations so that no one enter special characters to these form fields. Currently required is working.
