arg() dependent hidden field in AJAX form Basically, I have a hidden field I set using arg().

$form['slideid'] = array(
  '#type' =&gt; 'hidden',
  '#value' =&gt; arg(2)
);

$form['fid'] = array(
    '#type' =&gt; 'managed_file',
    '#title' =&gt; t('Image'),
    '#default_value' =&gt; "",
    '#size' =&gt; 40,
    '#description' =&gt; t("Image should be less than xxxxxxxxxxxx."),
    '#upload_location' =&gt; 'public://',
    '#prefix' =&gt; '&lt;div id="things"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
);


This value is set correctly once the form loads, but after a call to a AJAX field (managed_file), the form is refreshed and I get the wrong value in arg(2).

I have found arg(1) changed when doing AJAX, which doesn't give me any solution.

Is there any alternative that can be used, or can we skip the hidden field in the AJAX re-build? Is it possible to use a managed_file element without the AJAX submit?
As suggested by @AyeshK, I checked the $form_state in the hook_form before i set the value from arg()

 $form['slideid'] = array(
  '#type' =&gt; 'hidden',
  '#value' =&gt; (!empty($form_state['input']['slideid']) ? $form_state['input']['slideid'] : arg(2))
);


This could also be done in the hook_form_submit ...

function hook_form_submit($form, &amp;$form_state){

    if($form_state['values']['slideid'] != $form_state['input']['slideid']){
        $form_state['values']['slideid'] = (int)$form_state['input']['slideid'];
    }
   //====save the form data...

}


It looks like a crude fix, but it works for me.

Thank you for your help @AyeshK &amp; @kiamlaluno