How to add variables to Drupal.settings using form#attached? I found this example: http://deeson-online.co.uk/labs/how-use-formattached-javascript-setting-drupal-7-form-api

I tried:

   $form['#attached']['js'][] = array(
            'data' =&gt; array(
                'my_module' =&gt; array(
                    'xx_code' =&gt; 'dsadsad',
                    'xx_key' =&gt; 'sadasd',
                ),
            ),
            'type' =&gt; 'setting',
        );


but with no luck, Drupal.settings.my_module is undefined
Documentation is available:

Form API

$settings = array('id' =&gt; 'mymodule-element-1');

$form['#attached']['js'][] = array(
  'data' =&gt; array('mymodule' =&gt; $settings),
  'type' =&gt; 'setting',
);


Managing JavaScript in Drupal 7

$element['#attached']['js'][] = array(
  'type' =&gt; 'setting',
  'data' =&gt; array('myModule' =&gt; array('key' =&gt; 'value')),
);


Both are roughly the same as what OP (@drupality) said worked for him in a comment on Jun 14 2013.

The code in the original question that the OP said he tried but fails seems roughly the same as the working code, so I can't see what the original error was.