this error has been driving me completely mad for a few days. I at first thought it was specific to the media button and so switched to file managed and had the same issue.
Anyway, I have a form that generates, using AJAX, a set of form elements depending on the value of a radio button. The first option generates a file upload element and others basic text fields
The issue is that if I click upload, or with the media element 'attach', the ajax runs on that button and then the form element completely disappears, it's not in the DOM at all. I get no error messages. If I attempt to submit the form, the elements (even the ones that are still on the page) don't have any values in form_state.
I'm at a total loss with this.
Here is my form:
$node = node_load($nid);
// Getting the field_image widget - seemingly the only way to do this is to get every form element from node edit and then remove them. There is a ctools way to get individual elements but I couldn't get it to work
field_attach_form('node', $node, $form, $form_state, LANGUAGE_NONE);
foreach ($form as $key => $values) {
if (!in_array($key, array('artist', 'track', 'label', 'links', 'field_image')) && substr($key, 0, 1) != '#') {
$form[$key]['#access'] = FALSE;
}
}
// Save the field_image array
$field_image = $form['field_image'];
// Remove the original.
unset($form['field_image']);
The ajax radio button
$form['approve'] = array(
'#type' => 'radios',
'#title' => 'Approve, Reject or Reprocess?',
'#options' => array(
1 => 'Approve',
2 => 'Reject',
3 => 'Reprocess',
4 => 'Postpone',
),
'#required' => TRUE,
'#ajax' => array(
'callback' => 'post_approval_ajax_callback',
'wrapper' => 'approval-div',
'method' => 'replace',
'effect' => 'fade',
),
);
$form['approval_fieldset'] = array(
'#prefix' => '<div id="approval-div">',
'#suffix' => '</div>',
'#type' => 'fieldset',
);
And the first part of the switch that retrieves the image form
switch($form_state['values']['approve']) {
case 1:
$form['approval_fieldset']['information'] = array(
'#markup' => '<p>Approve this track? Please complete the following information about it, as much as possible.</p>',
);
$form['approval_fieldset']['artist'] = array(
'#type' => 'textfield',
'#title' => t('Artist'),
'#required' => TRUE,
'#default_value' => trim($details[0]),
);
$form['approval_fieldset']['track'] = array(
'#type' => 'textfield',
'#title' => t('Track'),
'#required' => TRUE,
'#default_value' => trim($details[1]),
);
$form['approval_fieldset']['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
);
$form['approval_fieldset']['links'] = array(
'#type' => 'text_format',
'#title' => t('Information'),
'#format' => 'full_html'
);
$form['approval_fieldset']['field_image'] = $field_image;
break;
My callback
function post_approval_ajax_callback($form, $form_state) {
return $form['approval_fieldset'];
}
Now it should be noted that this works absolutely perfectly without the AJAX generating the initial form. So there is something in either my ajax callback, or the file field button ajax callback that is incorrect.
Please help!
Comments
It's hard to give proper
It's hard to give proper information without seeing the functions that this code resides in. Drupal is all about context, the function names determine how things work. It's also hard to tell how the first and second blocks of code are related within your code. Please copy your actual code, and just remove anything that doesn't have relevance.
Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.
Sure
Sure
I've replaced the image field with just a normal managed file field to avoid confusion. When clicking the upload button the throbber appears and then the whole form field disappears. Clicking submit doesn't get me anywhere, dpm'ing the form_state in the validate hook shows that there are no values for any of the ajax generated fields, or even just array keys.
I tried adding the same field
I tried adding the same field to the examples ajax form to make sure it wasn't my form, and got
Notice: Undefined index: image in file_ajax_upload() (line 271 of /Users/Mike/Sites/Soul/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 280 of /Users/Mike/Sites/Soul/modules/file/file.module).
I updated my core, and all my modules, then applied the patch in here:
https://drupal.org/node/1336212
And tried to follow what was said here:
https://drupal.org/node/1526300#comment-5899988
But I don't think it applies, as I am not retrieving a node form, or trying to call user_profile_form(), although I might be misunderstanding?
So in the generate checkboxes form in the examples module I added the managed_file field
And upon clicking upload, the form element disappears and gives me those 2 errors. Bizarrely I didn't get those errors in my own form.
Looks like the theme was
Looks like the theme was stopping my error messages, I just tried it again and got these messages:
Notice: Undefined index: approve in post_approval_get_posts()
Notice: Undefined index: approve in post_approval_get_posts()
Notice: Undefined index: image in file_ajax_upload()
Notice: Undefined index: #suffix in file_ajax_upload()
I can't find anything that helps me with those errors messages. It seems like ajax form elements don't work in a ajax form...but that's surely a huge bug and would have been reported by now.
I've created a big report in the meantime, this is definitely not expected behaviour.
https://drupal.org/node/2210295
Hi michaelmallett,
Hi michaelmallett,
A response of the issue has been posted at below link.
https://drupal.org/node/2210295.
check it and reply whether it works for you or not.
With regards
Debarya Das
With Regards
Debarya Das
I have a custom form made in
I have a custom form made in drupal 7.I hv 1 text box which asks user to give an input.Then there is a submit button and another text box.Now I want that I will click on that submit button and the desired output will appear in that text box.The calculation for that output is done but it is not showing in that text box.Can anyone please help me solve the issue?
Hi Saatyanta,
Hi Saatyanta,
Can you share your code so that I can help you.
With Regards
Debarya Das
With Regards
Debarya Das