Hi i have a textfield form with attribute of "data-updated" the default is 0 If user clicks on textfield and fill it, "data-updated" changes to 1 with jQuery. On form submit the attribute remains 0 even if it changed to 1, how can i fix it?

Here is the code:

    $form['name'] = array(
        '#title' => t('Name'),
        '#type' => 'textfield',
        '#attributes' => array('data-updated' => 0, 'onclick' => array('jQuery(this).attr("data-updated", 1);')),

And here is the submit

print_r($form_state['complete form']['name']['#attributes']['data-updated']);

I always get 0 even if the jQuery update the attribute to 1 :/

  • HTML forms don't work that way - only input values are sent with the form submission, no other attributes
    – Clive
    Nov 19, 2015 at 9:51

1 Answer 1


As Clive said in the comment, you can't fix it. To do such things in the background of a form, use a hidden element:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.