API page: https://api.drupal.org/api/examples/form_example!form_example_states.inc...

I'm very surprised that this code has an #options array example using drupal_map_assoc() on arrays of translated strings. The keys of the array, which contain the data to be stored upon submit, should not be passed through t() and translated, otherwise the form will break and stored data will be corrupted on multilingual sites. The corrected array for the example of a 'select' element would be

array(
  'uk' => t('UK'),
  'other' => t('Other'),
)

https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen...
Similarly for the checkboxes example:

array(
  'SAT' => t('SAT'),
  'ACT' => t('ACT'),
)

These bad examples were copied over to the Form API documentation, so I've filed an issue there too: #2680521: Use of drupal_map_assoc to create options arrays is wrong in the form API reference.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

martin_q created an issue. See original summary.

martin_q’s picture

Issue summary: View changes
martin_q’s picture

Status: Needs review » Needs work
martin_q’s picture

Rerolled with corrected paths to sub-module files.

martin_q’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
martin_q’s picture

omkar06’s picture

Status: Needs review » Reviewed & tested by the community

Pretty straight forward. Patch tested and working as expected.

  • martin_q authored 4fd9689 on 7.x-1.x
    Issue #2680529 by martin_q: Use of drupal_map_assoc to create options...
valthebald’s picture

Committed and pushed to 7.x-1.x, thank you @martin_q!
8.x branch doesn't have this issue, so closing as fixed

valthebald’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.