Closed (fixed)
Project:
Token
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 Jan 2011 at 00:59 UTC
Updated:
26 Mar 2011 at 09:08 UTC
Jump to comment: Most recent file
In GA I'm using fields inside a table and they do not have a #title element. Therefor the form_error ends with The is using the following invalid tokens: [roles-invalid].. You can see the title is missing here. Otherwise I'm not able to set a title for this element or it would get shown in the table listing.
$form['googleanalytics_custom_var']['slots'][$i]['value'] = array(
'#default_value' => !empty($googleanalytics_custom_vars['slots'][$i]['value']) ? $googleanalytics_custom_vars['slots'][$i]['value'] : '',
'#description' => ($token_enabled ? t('The custom variable value. You may use tokens in this field.') : t('The custom variable value.')),
'#type' => 'textfield',
'#element_validate' => array('token_element_validate'),
'#token_types' => array('all'),
);
How can we solve this and make the form error helpful?
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | token_elements.patch | 706 bytes | hass |
| #6 | token_d6_add_title_invisible.patch | 1000 bytes | hass |
Comments
Comment #1
hass commentedComment #2
dave reidIn reality you shouldn't have form elements without a title as it provides no context to users that have to use screen readers, etc. You should be using:
Core itself seems to assume that #title is present, although not always. _form_validate() when checking the #required property of a field does the following:
But other element validation functions assume $element['#title'] exists:
http://api.drupal.org/api/drupal/modules--field--field.module/function/_...
http://api.drupal.org/api/drupal/modules--field--field.module/function/_...
http://api.drupal.org/api/drupal/modules--field--field.module/function/_...
Comment #3
dave reidThe D6 version of _form_validate also assumes $element['#title'] always exists.
Comment #4
hass commentedI was not aware of #title_display... I go with this in D7, but we cannot for D6.
I found more strange issue in token code... 'token_element_validate_token_context' is deprecated in D6, but in token D7 it is the only available validation function. Can you take a look to this, please? May need a new case...
Comment #5
hass commentedFollow up #1020066: D6 deprecated token_element_validate_token_context(), but the new token_element_validate is not in D7
Comment #6
hass commentedD6 patch attached adds $element['#title_invisible'] for D6. Are you able to accept this patch as a workaround for D6, please?
I have tested this and it WFM.
Comment #7
hass commentedMy patch for GA is in #1020314: Token validation shows broken error message and notice
Comment #8
dave reidCommitted the proper fix to D7.
http://drupal.org/cvs?commit=477968
Comment #9
dave reidHrm, I don't like '#title_invisible' for D6 since its not really supported. Does the same fix in http://drupal.org/cvs?commit=477968 help with this?
Comment #10
dave reidConfirmed, the same fix is good for Drupal 6, so committed to CVS: http://drupal.org/cvs?commit=477972
Comment #11
hass commentedYou have committed a broken patch... it need to be $element, but you used $elements. Patch need to be applied to both D7 and D6.
Comment #12
dave reidThanks, I had just noticed it too and committed a fix.