diff --git a/components/textfield.inc b/components/textfield.inc index 3a1cca8e..5eff2ab0 100644 --- a/components/textfield.inc +++ b/components/textfield.inc @@ -24,6 +24,7 @@ function _webform_defaults_textfield() { 'field_suffix' => '', 'disabled' => 0, 'unique' => 0, + 'uppercase' => 0, 'title_display' => 0, 'description' => '', 'description_above' => FALSE, @@ -61,6 +62,15 @@ function _webform_edit_textfield($component) { '#maxlength' => 1024, '#weight' => 0, ); + $form['uppercase'] = array( + '#type' => 'checkbox', + '#title' => t('Uppercase'), + '#return_value' => 1, + '#description' => t('When enabled the submitted value will be converted to uppercase.'), + '#weight' => 0, + '#default_value' => $component['extra']['uppercase'], + '#parents' => array('extra', 'uppercase'), + ); $form['display']['width'] = array( '#type' => 'textfield', '#title' => t('Width'), @@ -193,6 +203,9 @@ function _webform_render_textfield($component, $value = NULL, $filter = TRUE, $s if ($component['extra']['minlength'] > 0) { $element['#minlength'] = $component['extra']['minlength']; } + if ($component['extra']['uppercase']) { + $element['#value_callback'] = 'webform_textfield_uppercase_value'; + } if (isset($value[0])) { $element['#default_value'] = $value[0]; @@ -201,6 +214,25 @@ function _webform_render_textfield($component, $value = NULL, $filter = TRUE, $s return $element; } +/** + * Value callback for textfield form component to convert input to uppercase. + * + * @param array $element + * The textfield element. + * @param string|FALSE $input + * Input of the textfield component. + * @param array $form_state + * The form state for this request. + * + * @return string|void + * Input converted to uppercase or void if no input is given. + */ +function webform_textfield_uppercase_value($element, $input = FALSE, $form_state) { + if ($input) { + return strtoupper($input); + } +} + /** * Implements _webform_display_component(). */