function webform_email_validate in Webform 7.4
Validates an email form element.
Parameters
string $emails: An email or list of comma-seperated email addresses. Passed by reference. Empty emails will be eliminated, and mutiple addresses will be seperated with a comma and space.
string $form_name: The name of the form element to receive an error, in form_set_error format.
bool $allow_empty: TRUE if optional. FALSE if required.
bool $allow_multiple: TRUE if a list of emails is allowed. FALSE if only one.
bool $allow_tokens: TRUE if any token should be assumed to contain a valid e-mail address.
string $format: 'short', 'long', or NULL (for default) format. Long format has a name and the address in angle brackets.
Return value
int|bool The number of valid addresses found, or FALSE for an invalid email found.
3 calls to webform_email_validate()
- webform_email_address_validate in includes/
webform.emails.inc - Validate handler for webform_email_edit_form() and webform_emails_form().
- webform_email_edit_form_validate in includes/
webform.emails.inc - Validate handler for webform_email_edit_form().
- _webform_validate_email in components/
email.inc - A Drupal Form API Validation function.
File
- ./
webform.module, line 4688 - This module provides a simple way to create forms and questionnaires.
Code
function webform_email_validate(&$emails, $form_name, $allow_empty, $allow_multiple, $allow_tokens, $format = NULL) {
$nr_valid = webform_valid_email_address($emails, $allow_tokens, $format);
if ($nr_valid === FALSE) {
form_set_error($form_name, t('The entered e-mail address "@email" does not appear valid.', array(
'@email' => $emails,
)));
}
elseif ($nr_valid === 0 && !$allow_empty) {
form_set_error($form_name, t('When adding a new custom e-mail, the e-mail field is required.'));
}
elseif ($nr_valid > 1 && !$allow_multiple) {
form_set_error($form_name, t('Only one e-mail address is allowed.'));
}
return $nr_valid;
}