How to pass Javascript variable with form on submit? I want to pass a variable created with Javascript to $form_state so that I can use this variable in the form_submit function.

In an ajaxified form I can use:

Drupal.ajax[ajax_el].options.data._my_vars = JSON.stringify(js_object);


But how can I accomplish it in a non ajax form? Is there another possibility than using a hidden field? It might be possible to pass it to a field with #access =&gt; FALSE?

I would welcome every advice. Many thanks!

Daniel
Create a field for that variable, like this:

$form['_my_vars'] = array('#type' =&gt; 'hidden', '#default_value' =&gt; $_my_vars);


Whenever you are changing variable, update field's value.

Do not use 

'#access' =&gt; FALSE


The Form API Reference clarifies it:


  when FALSE, the element is not rendered and the user submitted value is not taken into consideration.