30 August 2012

Creating email field. The field is still textfield, you just have to make validation for the field.

Source code viewer
  1. // This is a field code.
  2. $form['email'] = array(
  3. '#type' => 'textfield',
  4. '#title' => t('Email'),
  5. '#element_validate' => array('HOOK_email_validate'),
  6. );
  7.  
  8. // This function is the validation function, you can rename it to anything
  9. function HOOK_email_validate($element, &$form_state, $form) {
  10. if (!valid_email_address($element['#value'])) {
  11. form_error($element, t('Please enter a valid email address.'));
  12. }
  13. }
Programming Language: PHP