Basically, I have a hidden field I set using arg()
.
$form['slideid'] = array(
'#type' => 'hidden',
'#value' => arg(2)
);
$form['fid'] = array(
'#type' => 'managed_file',
'#title' => t('Image'),
'#default_value' => "",
'#size' => 40,
'#description' => t("Image should be less than xxxxxxxxxxxx."),
'#upload_location' => 'public://',
'#prefix' => '<div id="things">',
'#suffix' => '</div>',
);
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?
systen/ajax
. You can store the slide ID in form_state, and check if it exists before overwriting (if it is already set, do not overwrite which means the form is rebuilt from Ajax callback). – AyeshK Sep 10 '15 at 9:11hook_form()
is the hook used by Drupal for content type, which means it is implemented from a module that creates a new content type (for example, the Blog or the Forum module). In the other cases, you are not implementinghook_form()
, but you are simply writing a form builder: a function that build a form using the form element provided from the form API. – kiamlaluno♦ Sep 10 '15 at 11:04hook_form()
are totally different from the parameters provided to a form builder, or other hooks. – kiamlaluno♦ Sep 10 '15 at 11:08