Closed (duplicate)
Project:
AHAH helper
Version:
6.x-2.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Sep 2009 at 14:45 UTC
Updated:
13 May 2010 at 14:32 UTC
I'm writing a Drupal 6 module from scratch that needs uploading files in Ajax and I'm apparently hit by an incompatibility between Ajax, AHAH helper and 'file' type forms fields.
Here is the code that reproduces the issue:
function cdp_perm() {
return array('access CDP application form');
}
function cdp_menu() {
$items = array();
$items['cdp/application'] = array(
'title' => t('Application form'),
'page callback' => 'drupal_get_form',
'page arguments' => array('cdp_application_form'),
'access callback' => TRUE,
'access arguments' => array('access CDP application form'),
'type' => MENU_CALLBACK
);
return $items;
}
function cdp_application_form($form_state) {
$form=array();
ahah_helper_register($form, $form_state);
$form['#ajax'] = array('enabled' => TRUE);
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['visual'] = array(
'#type' => 'fieldset',
'#title' => t('Visual of the project'),
'#prefix' => '<div id="visual-wrapper">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
$form['visual']['file'] = array(
'#type' => 'file',
'#title' => t('File'),
);
$form['visual']['upload'] = array(
'#type' => 'submit',
'#value' => t('Upload'),
'#submit' => array('cdp_uploadhack_submit'),
);
$form['submit'] = array('#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function cdp_application_form_submit($form, &$form_state) {
drupal_set_message(t('You have successfully submitted your project.'));
}
function cdp_uploadhack_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
if($file=file_save_upload('visual')) {
drupal_set_message(t('upload ok'));
}
else {
drupal_set_message(t('Nothing uploaded'), 'warning');
}
}
The upload form is broken, you get the extroardinary helpful error message "ajax.module: An unknown error has occurred.".
If you comment « $form['#ajax'] = array('enabled' => TRUE); », it just work but Ajax is indeed not supported anymore for error reporting.
It look related to http://drupal.org/node/399676 but the work-around does not work.
If anyone know how to fix it, I would be thankful.
Regards,
Comments
Comment #1
pobster commentedThe issue is likely that you're not following the instructions at all for ahah_helper. Try taking a look at the example module given; http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/ahah_helper...
You're supposed to use '#path' => ... to allow ahah_helper to do its magic.
Pobster
Comment #2
jbrown commentedI installed your module and it is working just fine on my local D6 install.
Are you able to replicate the problem on a publicly visible site so I could take a look?
Have you tried testing with smaller files?
Comment #3
brendoncrawford commentedI am the author of the AJAX module. AFAIK, the Ajax module and AHAH do not play nicely together. Getting them to do so, might be a fairly large task.
Comment #4
pavaniakella commentedHi,
Did u get any solution Now I am facing the same problem.
Please help me if u get any solution..
Regards,
Pavani
Comment #5
kenorb commented#83698: $source parameter in file_save_upload() not work as expected when field is in a fieldset with #tree set to TRUE