diff --git a/components/email.inc b/components/email.inc index f8fb148..2b46157 100644 --- a/components/email.inc +++ b/components/email.inc @@ -33,6 +33,10 @@ function _webform_defaults_email() { */ function _webform_theme_email() { return array( + 'webform_email' => array( + 'render element' => 'element', + 'file' => 'components/email.inc', + ), 'webform_display_email' => array( 'render element' => 'element', 'file' => 'components/email.inc', @@ -109,7 +113,7 @@ function _webform_edit_email_validate($element, &$form_state) { function _webform_render_email($component, $value = NULL, $filter = TRUE) { global $user; $element = array( - '#type' => 'textfield', + '#type' => 'webform_email', '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'], '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before', '#default_value' => _webform_filter_values($component['value']), @@ -147,6 +151,29 @@ function _webform_render_email($component, $value = NULL, $filter = TRUE) { } /** + * Theme function to render an email component. + */ +function theme_webform_email($variables) { + $element = $variables['element']; + + // This IF statement is mostly in place to allow our tests to set type="text" + // because SimpleTest does not support type="email". + if (!isset($element['#attributes']['type'])) { + $element['#attributes']['type'] = 'email'; + } + + // Convert properties to attributes on the element if set. + foreach (array('id', 'name', 'value', 'size') as $property) { + if (isset($element['#' . $property]) && $element['#' . $property] !== '') { + $element['#attributes'][$property] = $element['#' . $property]; + } + } + _form_set_class($element, array('form-text', 'form-email')); + + return ''; +} + +/** * A Drupal Form API Validation function. Validates the entered values from * email components on the client-side form. * diff --git a/components/number.inc b/components/number.inc index d533413..f66a76d 100644 --- a/components/number.inc +++ b/components/number.inc @@ -251,6 +251,7 @@ function _webform_render_number($component, $value = NULL, $filter = TRUE) { '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'], '#attributes' => $component['extra']['attributes'], '#element_validate' => array('_webform_validate_number'), + '#theme_wrappers' => array('webform_element'), '#min' => $component['extra']['min'], '#max' => $component['extra']['max'], '#step' => abs($component['extra']['step']), diff --git a/tests/webform.test b/tests/webform.test index 89d35b0..fd20046 100644 --- a/tests/webform.test +++ b/tests/webform.test @@ -398,6 +398,10 @@ class WebformTestCase extends DrupalWebTestCase { 'type' => 'email', 'value' => '%useremail', 'mandatory' => '0', + 'extra' => array( + // SimpleTest does not support type="email" input fields. + 'attributes' => array('type' => 'text'), + ), 'pid' => '0', 'weight' => '-5', ), diff --git a/webform.module b/webform.module index ea75f0a..d3182af 100644 --- a/webform.module +++ b/webform.module @@ -708,10 +708,14 @@ function webform_element_info() { $elements['webform_time'] = array('#input' => 'TRUE'); $elements['webform_grid'] = array('#input' => 'TRUE'); + $elements['webform_email'] = array( + '#input' => TRUE, + '#theme' => 'webform_email', + '#size' => 60, + ); $elements['webform_number'] = array( '#input' => TRUE, '#theme' => 'webform_number', - '#theme_wrappers' => array('webform_element'), '#min' => NULL, '#max' => NULL, '#step' => NULL,