| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: textfield.inc,v 1.21.2.4 2010/09/28 22:43:55 quicksketch Exp $ 3 4 /** 5 * @file 6 * Webform module textfield component. 7 */ 8 9 /** 10 * Implementation of _webform_defaults_component(). 11 */ 12 function _webform_defaults_textfield() { 13 return array( 14 'name' => '', 15 'form_key' => NULL, 16 'pid' => 0, 17 'weight' => 0, 18 'value' => '', 19 'mandatory' => 0, 20 'email' => 1, 21 'extra' => array( 22 'width' => '', 23 'maxlength' => '', 24 'field_prefix' => '', 25 'field_suffix' => '', 26 'disabled' => 0, 27 'unique' => 0, 28 'title_display' => 0, 29 'description' => '', 30 'attributes' => array(), 31 ), 32 ); 33 } 34 35 /** 36 * Implementation of _webform_theme_component(). 37 */ 38 function _webform_theme_textfield() { 39 return array( 40 'webform_display_textfield' => array( 41 'arguments' => array('element' => NULL), 42 ), 43 ); 44 } 45 46 /** 47 * Implementation of _webform_edit_component(). 48 */ 49 function _webform_edit_textfield($component) { 50 $form = array(); 51 $form['value'] = array( 52 '#type' => 'textfield', 53 '#title' => t('Default value'), 54 '#default_value' => $component['value'], 55 '#description' => t('The default value of the field.') . theme('webform_token_help'), 56 '#size' => 60, 57 '#maxlength' => 127, 58 '#weight' => 0, 59 ); 60 $form['display']['width'] = array( 61 '#type' => 'textfield', 62 '#title' => t('Width'), 63 '#default_value' => $component['extra']['width'], 64 '#description' => t('Width of the textfield.') . ' ' . t('Leaving blank will use the default size.'), 65 '#size' => 5, 66 '#maxlength' => 10, 67 '#weight' => 0, 68 '#parents' => array('extra', 'width'), 69 ); 70 $form['display']['field_prefix'] = array( 71 '#type' => 'textfield', 72 '#title' => t('Label placed to the left of the textfield'), 73 '#default_value' => $component['extra']['field_prefix'], 74 '#description' => t('Examples: $, #, -.'), 75 '#size' => 20, 76 '#maxlength' => 127, 77 '#weight' => 1.1, 78 '#parents' => array('extra', 'field_prefix'), 79 ); 80 $form['display']['field_suffix'] = array( 81 '#type' => 'textfield', 82 '#title' => t('Label placed to the right of the textfield'), 83 '#default_value' => $component['extra']['field_suffix'], 84 '#description' => t('Examples: lb, kg, %.'), 85 '#size' => 20, 86 '#maxlength' => 127, 87 '#weight' => 1.2, 88 '#parents' => array('extra', 'field_suffix'), 89 ); 90 $form['display']['disabled'] = array( 91 '#type' => 'checkbox', 92 '#title' => t('Disabled'), 93 '#return_value' => 1, 94 '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'), 95 '#weight' => 11, 96 '#default_value' => $component['extra']['disabled'], 97 '#parents' => array('extra', 'disabled'), 98 ); 99 $form['validation']['unique'] = array( 100 '#type' => 'checkbox', 101 '#title' => t('Unique'), 102 '#return_value' => 1, 103 '#description' => t('Check that all entered values for this field are unique. The same value is not allowed to be used twice.'), 104 '#weight' => 1, 105 '#default_value' => $component['extra']['unique'], 106 '#parents' => array('extra', 'unique'), 107 ); 108 $form['validation']['maxlength'] = array( 109 '#type' => 'textfield', 110 '#title' => t('Maxlength'), 111 '#default_value' => $component['extra']['maxlength'], 112 '#description' => t('Maximum length of the textfield value.'), 113 '#size' => 5, 114 '#maxlength' => 10, 115 '#weight' => 2, 116 '#parents' => array('extra', 'maxlength'), 117 ); 118 return $form; 119 } 120 121 /** 122 * Implementation of _webform_render_component(). 123 */ 124 function _webform_render_textfield($component, $value = NULL, $filter = TRUE) { 125 $element = array( 126 '#type' => $component['type'], 127 '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'], 128 '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : NULL, 129 '#default_value' => $filter ? _webform_filter_values($component['value'], NULL, NULL, NULL, FALSE) : $component['value'], 130 '#required' => $component['mandatory'], 131 '#weight' => $component['weight'], 132 '#field_prefix' => empty($component['extra']['field_prefix']) ? NULL : ($filter ? _webform_filter_xss($component['extra']['field_prefix']) : $component['extra']['field_prefix']), 133 '#field_suffix' => empty($component['extra']['field_suffix']) ? NULL : ($filter ? _webform_filter_xss($component['extra']['field_suffix']) : $component['extra']['field_prefix']), 134 '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'], 135 '#attributes' => $component['extra']['attributes'], 136 '#prefix' => '<div class="webform-component webform-component-' . $component['type'] . '" id="webform-component-' . $component['form_key'] . '">', 137 '#suffix' => '</div>', 138 '#pre_render' => array('webform_element_title_display'), 139 '#webform_component' => $component, 140 '#element_validate' => array(), 141 ); 142 143 if ($component['extra']['disabled']) { 144 $element['#attributes']['readonly'] = 'readonly'; 145 } 146 147 // Enforce uniqueness. 148 if ($component['extra']['unique']) { 149 $element['#element_validate'][] = 'webform_validate_unique'; 150 } 151 152 // Change the 'width' option to the correct 'size' option. 153 if ($component['extra']['width'] > 0) { 154 $element['#size'] = $component['extra']['width']; 155 } 156 if ($component['extra']['maxlength'] > 0) { 157 $element['#maxlength'] = $component['extra']['maxlength']; 158 } 159 160 if (isset($value)) { 161 $element['#default_value'] = $value[0]; 162 } 163 164 return $element; 165 } 166 167 /** 168 * Implementation of _webform_display_component(). 169 */ 170 function _webform_display_textfield($component, $value, $format = 'html') { 171 return array( 172 '#title' => $component['name'], 173 '#weight' => $component['weight'], 174 '#theme' => 'webform_display_textfield', 175 '#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'), 176 '#post_render' => array('webform_element_wrapper'), 177 '#field_prefix' => $component['extra']['field_prefix'], 178 '#field_suffix' => $component['extra']['field_suffix'], 179 '#format' => $format, 180 '#value' => isset($value[0]) ? $value[0] : '', 181 '#webform_component' => $component, 182 ); 183 } 184 185 /** 186 * Format the output of data for this component. 187 */ 188 function theme_webform_display_textfield($element) { 189 $prefix = $element['#format'] == 'html' ? filter_xss($element['#field_prefix']) : $element['#field_prefix']; 190 $suffix = $element['#format'] == 'html' ? filter_xss($element['#field_suffix']) : $element['#field_suffix']; 191 $value = $element['#format'] == 'html' ? check_plain($element['#value']) : $element['#value']; 192 return $value ? ($prefix . $value . $suffix) : ' '; 193 } 194 195 /** 196 * Implementation of _webform_analysis_component(). 197 */ 198 function _webform_analysis_textfield($component, $sids = array()) { 199 $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array(); 200 $sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : ""; 201 $query = 'SELECT data ' . 202 ' FROM {webform_submitted_data} ' . 203 ' WHERE nid = %d ' . 204 ' AND cid = %d ' . $sidfilter; 205 $nonblanks = 0; 206 $submissions = 0; 207 $wordcount = 0; 208 209 $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids)); 210 while ($data = db_fetch_array($result)) { 211 if (drupal_strlen(trim($data['data'])) > 0) { 212 $nonblanks++; 213 $wordcount += str_word_count(trim($data['data'])); 214 } 215 $submissions++; 216 } 217 218 $rows[0] = array(t('Left Blank'), ($submissions - $nonblanks)); 219 $rows[1] = array(t('User entered value'), $nonblanks); 220 $rows[2] = array(t('Average submission length in words (ex blanks)'), ($nonblanks != 0 ? number_format($wordcount/$nonblanks, 2) : '0')); 221 return $rows; 222 } 223 224 /** 225 * Implementation of _webform_table_component(). 226 */ 227 function _webform_table_textfield($component, $value) { 228 return check_plain(empty($value[0]) ? '' : $value[0]); 229 } 230 231 /** 232 * Implementation of _webform_csv_headers_component(). 233 */ 234 function _webform_csv_headers_textfield($component, $export_options) { 235 $header = array(); 236 $header[0] = ''; 237 $header[1] = ''; 238 $header[2] = $component['name']; 239 return $header; 240 } 241 242 /** 243 * Implementation of _webform_csv_data_component(). 244 */ 245 function _webform_csv_data_textfield($component, $export_options, $value) { 246 return !isset($value[0]) ? '' : $value[0]; 247 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |