This is a really strange one, I've created a custom form using the multi step form method. So there are various AJAX calls to handler functions that return certain sections of the form back to containers and replace the HTML.
My form works great has a lot of complexity to it and the speed is fantastic. A recent addition to said form is to be able to upload a PDF, simple I thought! Added my manged_file field and all looked great. However I'd missed that now my page was reloading, AJAX requests were no longer in the Firebug console and instead seemed to be in the POST somehow. I don't fully understand how the AJAX is still working but it is slower that's for sure!
This is a problem I think we could live with a bit of slowness but then I noticed on a full form submission it was breaking a second form outside of this form. Basically it's too big of an issue to live with now.
I've tried a few things, one a standard file field, two a markup field with a raw
<input type="file" />
just to see what happened and I experienced the exact same issue as using the form API. This confirms to me that this is not caused by some added javascript from Drupal but a problem with the input itself.
So my question is why does a file field break the AJAX in my form?
Rather awkwardly I can't just paste all my code here as the data is protected and technically not my property. I'm not sure it's needed but I've thrown together a quick bit of code that should demonstrate my issue.
function vv_test_menu(){
$items = array();
$items['vvtest'] = array(
'page callback' => 'vv_test_page',
'access arguments' => array('access content'),
'page arguments' => array(false),
'description' => t('Test page for code.'),
'type' => MENU_CALLBACK,
);
return $items;
}
function vv_test_page(){
$content = 'This demonstrates the file field breaking the AJAX.';
$content .= render(drupal_get_form('vv_test_form'));
return $content;
}
function vv_test_form($form, &$form_state){
$form['#tree'] = TRUE;
$form['#prefix'] = '<div id="container">';
$form['#suffix'] = '</div>';
$form['job_number'] = array(
'#type' => 'textfield',
'#title' => t('Job number'),
'#required' => TRUE
);
if($form_state['triggering_element']['#ajax']['callback'] == t('vv_test_call')){
$form['result'] = array(
'#markup' => '<div id="container">You entered: '.print_r($form_state['values']['job_number'], true).'</div>'
);
}
// - Comment this field in and out to see the problem
$form['pdf'] = array(
'#type' => 'file',
'#title' => t('A file field')
);
$form['sync'] = array(
'#type' => 'button',
'#name' => 'sync',
'#value' => t('Sync'),
'#ajax' => array(
'callback' => 'vv_test_call',
'wrapper' => 'container'
)
);
return $form;
}
function vv_test_call($form, &$form_state){
$form_state['rebuild'] = FALSE;
return $form;
}