How to get a node object/id from theme functions when the form is ajaxified? I used theme_radio() hook to change the html code of my radio buttons in ubercart attributes form to get something like that:



The code I used in theme_radio function to display this is:

//We modify only radio input in ubercart attributes forms
  if(isset($variables['element']['#parents'])){

    if(($variables['element']['#parents']['0']=='attributes')&amp;&amp;($variables['element']['#parents']['1']=='8')&amp;&amp;($variables['element']['#type']=='radio')){

      $node = menu_get_object();

      $position = $variables['element']['#return_value'];

      //We load content from field collection
      $field_collection_entity = field_collection_item_load($node-&gt;field_colors['und'][$position]['value']);

      //We extract color name from field collection
      $color_code = $field_collection_entity-&gt;field_color_code['und'][0]['rgb'];

      $pellet_html = '&lt;span class="attributes-pellet" style="background: none repeat scroll 0% 0% '.$color_code.';"&gt;&lt;/span&gt;';
    }else{
      $pellet_html = '';
    }
  }else{
    $pellet_html = '';
  };


So everything works well when I load the page. 

The problem occurs when I select something in form. As the form is ajaxified, actually when I click either on colors or sizes inputs, the form reload and my function is no more able to retrieve the node object with:

$node = menu_get_object();


or with:

if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
  $nid = arg(1);
  if ($nid) {
    $node = node_load($nid);
  }
}


After I clicked in a option, the color inputs get back to initial state:



So how to retrieve node object/id from a theme function when form is ajaxified??

You can check the form there:

http://www.zanonymes.krown.ch/collections/les-accroch%C3%A9s
You can try to store the node->nid in a hidden field on page load. When your ajax call is executed, you can load the node from the hidden field instead of the menu_get_object.