Révision a45e4bc1
Ajouté par Assos Assos il y a presque 9 ans
drupal7/sites/all/modules/webform/components/email.inc | ||
---|---|---|
15 | 15 |
'pid' => 0, |
16 | 16 |
'weight' => 0, |
17 | 17 |
'value' => '', |
18 |
'mandatory' => 0,
|
|
18 |
'required' => 0,
|
|
19 | 19 |
'extra' => array( |
20 |
'multiple' => 0, |
|
21 |
'format' => 'short', |
|
20 | 22 |
'width' => '', |
21 | 23 |
'unique' => 0, |
22 | 24 |
'disabled' => 0, |
23 | 25 |
'title_display' => 0, |
24 | 26 |
'description' => '', |
27 |
'placeholder' => '', |
|
25 | 28 |
'attributes' => array(), |
26 | 29 |
'private' => FALSE, |
30 |
'analysis' => FALSE, |
|
27 | 31 |
), |
28 | 32 |
); |
29 | 33 |
} |
... | ... | |
52 | 56 |
'#type' => 'textfield', |
53 | 57 |
'#title' => t('Default value'), |
54 | 58 |
'#default_value' => $component['value'], |
55 |
'#description' => t('The default value of the field.') . theme('webform_token_help'), |
|
59 |
'#description' => t('The default value of the field.') . ' ' . theme('webform_token_help'),
|
|
56 | 60 |
'#size' => 60, |
57 | 61 |
'#maxlength' => 127, |
58 | 62 |
'#weight' => 0, |
59 |
'#attributes' => ($component['value'] == '%useremail' && count(form_get_errors()) == 0) ? array('disabled' => TRUE) : array(),
|
|
63 |
'#attributes' => ($component['value'] == '[current-user:mail]' && count(form_get_errors()) == 0) ? array('disabled' => TRUE) : array(),
|
|
60 | 64 |
'#id' => 'email-value', |
61 | 65 |
); |
62 | 66 |
$form['user_email'] = array( |
63 | 67 |
'#type' => 'checkbox', |
64 | 68 |
'#title' => t('User email as default'), |
65 |
'#default_value' => $component['value'] == '%useremail' ? 1 : 0,
|
|
69 |
'#default_value' => $component['value'] == '[current-user:mail]' ? 1 : 0,
|
|
66 | 70 |
'#description' => t('Set the default value of this field to the user email, if he/she is logged in.'), |
67 |
'#attributes' => array('onclick' => 'getElementById("email-value").value = (this.checked ? "%useremail" : ""); getElementById("email-value").disabled = this.checked;'),
|
|
71 |
'#attributes' => array('onclick' => 'getElementById("email-value").value = (this.checked ? "[current-user:mail]" : ""); getElementById("email-value").disabled = this.checked;'),
|
|
68 | 72 |
'#weight' => 0, |
69 | 73 |
'#element_validate' => array('_webform_edit_email_validate'), |
70 | 74 |
); |
75 |
$form['extra']['multiple'] = array( |
|
76 |
'#type' => 'checkbox', |
|
77 |
'#title' => t('Multiple'), |
|
78 |
'#default_value' => $component['extra']['multiple'], |
|
79 |
'#description' => t('Allow multiple e-mail addresses, separated by commas.'), |
|
80 |
'#weight' => 0, |
|
81 |
); |
|
82 |
if (webform_variable_get('webform_email_address_format') == 'long') { |
|
83 |
$form['extra']['format'] = array( |
|
84 |
'#type' => 'radios', |
|
85 |
'#title' => t('Format'), |
|
86 |
'#options' => array( |
|
87 |
'long' => t('Allow long format: "Example Name" <name@example.com>'), |
|
88 |
'short' => t('Short format only: name@example.com'), |
|
89 |
), |
|
90 |
'#default_value' => $component['extra']['format'], |
|
91 |
'#description' => t('Not all servers support the "long" format.'), |
|
92 |
); |
|
93 |
} |
|
71 | 94 |
$form['display']['width'] = array( |
72 | 95 |
'#type' => 'textfield', |
73 | 96 |
'#title' => t('Width'), |
... | ... | |
77 | 100 |
'#maxlength' => 10, |
78 | 101 |
'#parents' => array('extra', 'width'), |
79 | 102 |
); |
103 |
$form['display']['placeholder'] = array( |
|
104 |
'#type' => 'textfield', |
|
105 |
'#title' => t('Placeholder'), |
|
106 |
'#default_value' => $component['extra']['placeholder'], |
|
107 |
'#description' => t('The placeholder will be shown in the field until the user starts entering a value.') . ' ' . t('Often used for example values, such as "john@example.com".'), |
|
108 |
'#parents' => array('extra', 'placeholder'), |
|
109 |
); |
|
80 | 110 |
$form['display']['disabled'] = array( |
81 | 111 |
'#type' => 'checkbox', |
82 | 112 |
'#title' => t('Disabled'), |
... | ... | |
103 | 133 |
*/ |
104 | 134 |
function _webform_edit_email_validate($element, &$form_state) { |
105 | 135 |
if ($form_state['values']['user_email']) { |
106 |
$form_state['values']['value'] = '%useremail';
|
|
136 |
$form_state['values']['value'] = '[current-user:mail]';
|
|
107 | 137 |
} |
108 | 138 |
} |
109 | 139 |
|
110 | 140 |
/** |
111 | 141 |
* Implements _webform_render_component(). |
112 | 142 |
*/ |
113 |
function _webform_render_email($component, $value = NULL, $filter = TRUE) { |
|
143 |
function _webform_render_email($component, $value = NULL, $filter = TRUE, $submission = NULL) {
|
|
114 | 144 |
global $user; |
115 | 145 |
$node = isset($component['nid']) ? node_load($component['nid']) : NULL; |
116 | 146 |
|
117 | 147 |
$element = array( |
118 | 148 |
'#type' => 'webform_email', |
119 |
'#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
|
|
149 |
'#title' => $filter ? webform_filter_xss($component['name']) : $component['name'], |
|
120 | 150 |
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before', |
121 |
'#default_value' => $filter ? _webform_filter_values($component['value'], $node) : $component['value'],
|
|
122 |
'#required' => $component['mandatory'],
|
|
151 |
'#default_value' => $filter ? webform_replace_tokens($component['value'], $node) : $component['value'],
|
|
152 |
'#required' => $component['required'],
|
|
123 | 153 |
'#weight' => $component['weight'], |
124 |
'#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
|
|
154 |
'#description' => $filter ? webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'], |
|
125 | 155 |
'#attributes' => $component['extra']['attributes'], |
126 | 156 |
'#element_validate' => array('_webform_validate_email'), |
127 | 157 |
'#theme_wrappers' => array('webform_element'), |
128 | 158 |
'#translatable' => array('title', 'description'), |
129 | 159 |
); |
130 | 160 |
|
161 |
if ($component['required']) { |
|
162 |
$element['#attributes']['required'] = 'required'; |
|
163 |
} |
|
164 |
|
|
131 | 165 |
// Add an e-mail class for identifying the difference from normal textfields. |
132 | 166 |
$element['#attributes']['class'][] = 'email'; |
133 | 167 |
|
... | ... | |
136 | 170 |
$element['#element_validate'][] = 'webform_validate_unique'; |
137 | 171 |
} |
138 | 172 |
|
139 |
if (isset($value)) { |
|
173 |
if ($component['extra']['format'] == 'long') { |
|
174 |
// html5 email elements enforce short-form email validation in addition to |
|
175 |
// pattern validation. This means that long format email addresses must be |
|
176 |
// rendered as text. |
|
177 |
$element['#attributes']['type'] = 'text'; |
|
178 |
|
|
179 |
// html5 patterns have implied delimters and start and end patterns. |
|
180 |
// The are also case sensitive, not global, and not multi-line. |
|
181 |
// See https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation |
|
182 |
// See http://stackoverflow.com/questions/19605773/html5-email-validation |
|
183 |
$address = '[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*'; |
|
184 |
$name = '("[^<>"]*?"|[^<>",]*?)'; |
|
185 |
$short_long = "($name *<$address>|$address)"; |
|
186 |
$element['#attributes']['pattern'] = $component['extra']['multiple'] |
|
187 |
? "$short_long(, *$short_long)*" |
|
188 |
: $short_long; |
|
189 |
} |
|
190 |
elseif ($component['extra']['multiple']) { |
|
191 |
$element['#attributes']['multiple'] = 'multiple'; |
|
192 |
} |
|
193 |
|
|
194 |
if (isset($value[0])) { |
|
140 | 195 |
$element['#default_value'] = $value[0]; |
141 | 196 |
} |
142 | 197 |
|
198 |
if ($component['extra']['placeholder']) { |
|
199 |
$element['#attributes']['placeholder'] = $component['extra']['placeholder']; |
|
200 |
} |
|
201 |
|
|
143 | 202 |
if ($component['extra']['disabled']) { |
144 | 203 |
if ($filter) { |
145 | 204 |
$element['#attributes']['readonly'] = 'readonly'; |
... | ... | |
193 | 252 |
*/ |
194 | 253 |
function _webform_validate_email($form_element, &$form_state) { |
195 | 254 |
$component = $form_element['#webform_component']; |
196 |
$value = trim($form_element['#value']);
|
|
197 |
if ($value !== '' && !valid_email_address($value)) {
|
|
198 |
form_error($form_element, t('%value is not a valid email address.', array('%value' => $value)));
|
|
199 |
}
|
|
200 |
else {
|
|
201 |
form_set_value($form_element, $value, $form_state);
|
|
202 |
}
|
|
255 |
$format = webform_variable_get('webform_email_address_format') == 'long' ? $component['extra']['format'] : 'short';
|
|
256 |
webform_email_validate($form_element['#value'],
|
|
257 |
implode('][', $form_element ['#parents']),
|
|
258 |
TRUE, // Required validation is done elsewhere.
|
|
259 |
$component['extra']['multiple'],
|
|
260 |
FALSE, // No tokens are allowed in user input.
|
|
261 |
$format);
|
|
203 | 262 |
} |
204 | 263 |
|
205 | 264 |
/** |
206 | 265 |
* Implements _webform_display_component(). |
207 | 266 |
*/ |
208 |
function _webform_display_email($component, $value, $format = 'html') { |
|
267 |
function _webform_display_email($component, $value, $format = 'html', $submission = array()) {
|
|
209 | 268 |
return array( |
210 | 269 |
'#title' => $component['name'], |
270 |
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before', |
|
211 | 271 |
'#weight' => $component['weight'], |
212 | 272 |
'#theme' => 'webform_display_email', |
213 | 273 |
'#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'), |
... | ... | |
229 | 289 |
/** |
230 | 290 |
* Implements _webform_analysis_component(). |
231 | 291 |
*/ |
232 |
function _webform_analysis_email($component, $sids = array()) { |
|
292 |
function _webform_analysis_email($component, $sids = array(), $single = FALSE, $join = NULL) {
|
|
233 | 293 |
$query = db_select('webform_submitted_data', 'wsd', array('fetch' => PDO::FETCH_ASSOC)) |
234 | 294 |
->fields('wsd', array('no', 'data')) |
235 |
->condition('nid', $component['nid']) |
|
236 |
->condition('cid', $component['cid']); |
|
295 |
->condition('wsd.nid', $component['nid'])
|
|
296 |
->condition('wsd.cid', $component['cid']);
|
|
237 | 297 |
|
238 | 298 |
if (count($sids)) { |
239 |
$query->condition('sid', $sids, 'IN'); |
|
299 |
$query->condition('wsd.sid', $sids, 'IN'); |
|
300 |
} |
|
301 |
|
|
302 |
if ($join) { |
|
303 |
$query->innerJoin($join, 'ws2_', 'wsd.sid = ws2_.sid'); |
|
240 | 304 |
} |
241 | 305 |
|
242 | 306 |
$nonblanks = 0; |
... | ... | |
254 | 318 |
|
255 | 319 |
$rows[0] = array(t('Left Blank'), ($submissions - $nonblanks)); |
256 | 320 |
$rows[1] = array(t('User entered value'), $nonblanks); |
257 |
$rows[2] = array(t('Average submission length in words (ex blanks)'), ($nonblanks != 0 ? number_format($wordcount/$nonblanks, 2) : '0')); |
|
258 |
return $rows; |
|
321 |
|
|
322 |
$other[0] = array(t('Average submission length in words (ex blanks)'), ($nonblanks != 0 ? number_format($wordcount/$nonblanks, 2) : '0')); |
|
323 |
|
|
324 |
return array( |
|
325 |
'table_rows' => $rows, |
|
326 |
'other_data' => $other, |
|
327 |
); |
|
328 |
|
|
259 | 329 |
} |
260 | 330 |
|
261 | 331 |
/** |
... | ... | |
273 | 343 |
$header = array(); |
274 | 344 |
$header[0] = ''; |
275 | 345 |
$header[1] = ''; |
276 |
$header[2] = $component['name']; |
|
346 |
$header[2] = $export_options['header_keys'] ? $component['form_key'] : $component['name'];
|
|
277 | 347 |
return $header; |
278 | 348 |
} |
279 | 349 |
|
Formats disponibles : Unified diff
Update webform to 4.10