| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * Webform module textfield component. 6 */ 7 8 /** 9 * Implements _webform_defaults_component(). 10 */ 11 function _webform_defaults_textfield() { 12 return array( 13 'name' => '', 14 'form_key' => NULL, 15 'pid' => 0, 16 'weight' => 0, 17 'value' => '', 18 'mandatory' => 0, 19 'extra' => array( 20 'width' => '', 21 'maxlength' => '', 22 'field_prefix' => '', 23 'field_suffix' => '', 24 'disabled' => 0, 25 'unique' => 0, 26 'title_display' => 0, 27 'description' => '', 28 'attributes' => array(), 29 'private' => FALSE, 30 ), 31 ); 32 } 33 34 /** 35 * Implements _webform_theme_component(). 36 */ 37 function _webform_theme_textfield() { 38 return array( 39 'webform_display_textfield' => array( 40 'arguments' => array('element' => NULL), 41 'file' => 'components/textfield.inc', 42 ), 43 ); 44 } 45 46 /** 47 * Implements _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' => 1024, 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('Prefix text placed to the left of the field'), 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('Postfix text placed to the right of the field'), 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 * Implements _webform_render_component(). 123 */ 124 function _webform_render_textfield($component, $value = NULL, $filter = TRUE) { 125 $node = isset($component['nid']) ? node_load($component['nid']) : NULL; 126 127 $element = array( 128 '#type' => 'textfield', 129 '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'], 130 '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before', 131 '#default_value' => $filter ? _webform_filter_values($component['value'], $node, NULL, NULL, FALSE) : $component['value'], 132 '#required' => $component['mandatory'], 133 '#weight' => $component['weight'], 134 '#field_prefix' => empty($component['extra']['field_prefix']) ? NULL : ($filter ? _webform_filter_xss($component['extra']['field_prefix']) : $component['extra']['field_prefix']), 135 '#field_suffix' => empty($component['extra']['field_suffix']) ? NULL : ($filter ? _webform_filter_xss($component['extra']['field_suffix']) : $component['extra']['field_suffix']), 136 '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'], 137 '#attributes' => $component['extra']['attributes'], 138 '#theme_wrappers' => array('webform_element_wrapper'), 139 '#pre_render' => array('webform_element_title_display'), 140 '#post_render' => array('webform_element_wrapper'), 141 '#translatable' => array('title', 'description', 'field_prefix', 'field_suffix'), 142 ); 143 144 if ($component['extra']['disabled']) { 145 if ($filter) { 146 $element['#attributes']['readonly'] = 'readonly'; 147 } 148 else { 149 $element['#disabled'] = TRUE; 150 } 151 } 152 153 // Enforce uniqueness. 154 if ($component['extra']['unique']) { 155 $element['#element_validate'][] = 'webform_validate_unique'; 156 } 157 158 // Change the 'width' option to the correct 'size' option. 159 if ($component['extra']['width'] > 0) { 160 $element['#size'] = $component['extra']['width']; 161 } 162 if ($component['extra']['maxlength'] > 0) { 163 $element['#maxlength'] = $component['extra']['maxlength']; 164 } 165 166 if (isset($value)) { 167 $element['#default_value'] = $value[0]; 168 } 169 170 return $element; 171 } 172 173 /** 174 * Implements _webform_display_component(). 175 */ 176 function _webform_display_textfield($component, $value, $format = 'html') { 177 return array( 178 '#title' => $component['name'], 179 '#weight' => $component['weight'], 180 '#theme' => 'webform_display_textfield', 181 '#theme_wrappers' => $format == 'html' ? array('webform_element', 'webform_element_wrapper') : array('webform_element_text'), 182 '#post_render' => array('webform_element_wrapper'), 183 '#field_prefix' => $component['extra']['field_prefix'], 184 '#field_suffix' => $component['extra']['field_suffix'], 185 '#format' => $format, 186 '#value' => isset($value[0]) ? $value[0] : '', 187 '#translatable' => array('title', 'field_prefix', 'field_suffix'), 188 ); 189 } 190 191 /** 192 * Format the output of data for this component. 193 */ 194 function theme_webform_display_textfield($element) { 195 $prefix = $element['#format'] == 'html' ? filter_xss($element['#field_prefix']) : $element['#field_prefix']; 196 $suffix = $element['#format'] == 'html' ? filter_xss($element['#field_suffix']) : $element['#field_suffix']; 197 $value = $element['#format'] == 'html' ? check_plain($element['#value']) : $element['#value']; 198 return $value !== '' ? ($prefix . $value . $suffix) : ' '; 199 } 200 201 /** 202 * Implements _webform_analysis_component(). 203 */ 204 function _webform_analysis_textfield($component, $sids = array()) { 205 $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array(); 206 $sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : ""; 207 $query = 'SELECT data ' . 208 ' FROM {webform_submitted_data} ' . 209 ' WHERE nid = %d ' . 210 ' AND cid = %d ' . $sidfilter; 211 $nonblanks = 0; 212 $submissions = 0; 213 $wordcount = 0; 214 215 $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids)); 216 while ($data = db_fetch_array($result)) { 217 if (drupal_strlen(trim($data['data'])) > 0) { 218 $nonblanks++; 219 $wordcount += str_word_count(trim($data['data'])); 220 } 221 $submissions++; 222 } 223 224 $rows[0] = array(t('Left Blank'), ($submissions - $nonblanks)); 225 $rows[1] = array(t('User entered value'), $nonblanks); 226 $rows[2] = array(t('Average submission length in words (ex blanks)'), ($nonblanks != 0 ? number_format($wordcount/$nonblanks, 2) : '0')); 227 return $rows; 228 } 229 230 /** 231 * Implements _webform_table_component(). 232 */ 233 function _webform_table_textfield($component, $value) { 234 return check_plain(empty($value[0]) ? '' : $value[0]); 235 } 236 237 /** 238 * Implements _webform_csv_headers_component(). 239 */ 240 function _webform_csv_headers_textfield($component, $export_options) { 241 $header = array(); 242 $header[0] = ''; 243 $header[1] = ''; 244 $header[2] = $component['name']; 245 return $header; 246 } 247 248 /** 249 * Implements _webform_csv_data_component(). 250 */ 251 function _webform_csv_data_textfield($component, $export_options, $value) { 252 return !isset($value[0]) ? '' : $value[0]; 253 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |