Hi,

I've just notice that the upload file field return an AJAX error, but the file upload works well. This only affects to the callback function i think.

Does anybody a solution for this?

Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rogical’s picture

+1

jide’s picture

Title: AJAX Callback does not work after an upload w/ Field File (cck core in drupal 7) » AJAX Callbacks do not include node.pages.inc and throw an error
Priority: Normal » Major
Status: Active » Needs review

Had the same issue. This is because the "node.pages.inc" include file is not included in the AJAX callback (but I have no clue why for the moment). The issue will probably raise with other ajax callbacks.

As a quick and simple fix, you can do this in a custom module (or in the formblock module itself) :

function MYMODULE_init() {
  if ($_GET['q'] == 'system/ajax' && preg_match('/^[a-z_]+_node_form/', $_POST['form_id'])) {
    module_load_include('inc', 'node', 'node.pages');
  }
}

For a real fix, the formblock module should probably do something like traversing all form elements, looking for the '#ajax' property and use a custom callback that includes the needed file. But that may be a little overwhelming, so this simple fix may be enough.

Renaming the issue and bumping as major since this can potentially break the form entirely.

bryancasler’s picture

subscribe

breckenr’s picture

+1

boringtao’s picture

the same issue occurs when upload images on register form too. any idea how to fix it?

rawrzors’s picture

Could you please elaborate on this fix? When you say "or in the formblock module itself," which file do you mean?

jide’s picture

I mean in formblock.module.

rawrzors’s picture

I'm sorry to trouble you, but I do not know too much about editing modules.

I have tried to copy & paste the code you provided in the end of the formblock.module, but it causes a parse error on my site. Could you please explain in a bit more detail what to do?

Thank you for your time.

jide’s picture

Do not include , and replace "MYMODULE" with "formblock".

rawrzors’s picture

I did as you instructed and only part of the error went away.

Here is a screenshot:
http://img192.imageshack.us/img192/273/errorzw.png

Error occurs when I press upload.
Not sure if I should create a new topic for this part.

jide’s picture

Put exactly this at the end of formblock.module :

function formblock_init() {
  if ($_GET['q'] == 'system/ajax' && preg_match('/^[a-z_]+_node_form/', $_POST['form_id'])) {
    module_load_include('inc', 'node', 'node.pages');
  }
}
jide’s picture

Ah, and clear the cache after that !

rawrzors’s picture

FileSize
1.65 KB

Jide,

I have followed your instructions and I am still having the problem.

I have attached my formblock.module, if you have some free time, could you please look at it?

Thank you.

jide’s picture

That's odd, it works for me... Anyway, this issue deserves a real fix, I may have a solution that I will post when I get some time.

mikey_p’s picture

I'll see if I can find an appropriate fix for this soon, but the problem doesn't appear to be with formblock module (the form should be using $form_state['build_info']['files']['form'] if it needs a specific file).

mikey_p’s picture

sun’s picture

Status: Needs review » Active
Issue tags: -ajax form

form_load_include() is your friend, but is only needed in case the form doesn't reside in the 'file' specified in the menu router definition of the current/initial request.

(which seems to be the case here)

(lastly, no patch here? » active)

jide’s picture

@sun: So if we use a custom path instead of system/ajax, with a callback directly inside the module file, will the needed include files be included ? I believe I saw something like that in media.module.

sun’s picture

The AJAX callback menu path is too late. The include file of a form needs to be cached with the form on the page the form appears in the first place.

E.g., you have the node form as a block on the front page. The front page does not load node.pages.inc normally. To build and render this form, you have to include node.pages.inc. This file inclusion needs to be recorded in $form_state when the form is built.

Only that way, a potential AJAX request triggered by a form interaction is going to hit system/ajax (!= front page), which loads the $form_state from cache_form (by form_build_id), checks whether any include files are recorded in $form_state, and if so loads them, and lastly, processes the input and rebuilds the form. (All of this is built-into system/ajax, nothing you'd have to implement yourself.)

So it's really about registering the needed include file only. Normally, that node form would be loaded on node/add/type, and that menu router item defines node.pages.inc as include file. The Form/AJAX system automatically takes over that include file definition from the menu router item to simplify the DX in 90% of all cases.

Lastly, kinda off-topic for this issue, but I wanted to note that you'll have to disable block caching for these blocks - as otherwise, the cached form possibly expires earlier than the cached block, and many other unexpected hiccups.

tbenice’s picture

patch that works for me...

rawrzors’s picture

tbenice,

I have tried your patch, but the problem still remains.

Anyone know of a similar module that I can use?

Thanks.

jpfeifer’s picture

subscribe

jpfeifer’s picture

Strange finding. I've tried all the patches and notice that when I clear all caches under admin/config/development/performance, I can upload one image. Any subsequent tries give me the same error.

Is there any other module like this or fix?

J

ansbar’s picture

As jpfeifer said, have tried all patches and fixes, non work.

FYI my problem occur when clicking the "upload"-button on a add-node-form.

Error:
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'node_form' was given i drupal_retrieve_form()

Would really appreciate if anyone could figure out a working fix ;)

sahaj’s picture

Had the same problem, but with the country selection inside an 'Address field'. Fix #11 solved it.

jisuo’s picture

I tried both #11 and #20, but the ajax uploading of images still won't work.

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'node_form' not found or invalid function name in drupal_retrieve_form() (line 785 of D:\xampp\htdocs\standardweb\includes\form.inc).
Notice: Undefined index: #node in comment_form_node_form_alter() (line 1193 of D:\xampp\htdocs\standardweb\modules\comment\comment.module).
Notice: Trying to get property of non-object in comment_form_node_form_alter() (line 1210 of D:\xampp\htdocs\standardweb\modules\comment\comment.module).
Notice: Undefined index: #node in i18n_node_form_node_form_alter() (line 424 of D:\xampp\htdocs\standardweb\sites\all\modules\contrib\i18n\i18n_node\i18n_node.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 612 of D:\xampp\htdocs\standardweb\modules\menu\menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 612 of D:\xampp\htdocs\standardweb\modules\menu\menu.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 613 of D:\xampp\htdocs\standardweb\modules\menu\menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 613 of D:\xampp\htdocs\standardweb\modules\menu\menu.module).
Notice: Undefined index: #node in translation_form_node_form_alter() (line 126 of D:\xampp\htdocs\standardweb\modules\translation\translation.module).
Notice: Trying to get property of non-object in translation_form_node_form_alter() (line 126 of D:\xampp\htdocs\standardweb\modules\translation\translation.module).
Notice: Undefined index: type in xmlsitemap_node_form_node_form_alter() (line 136 of D:\xampp\htdocs\standardweb\sites\all\modules\contrib\xmlsitemap\xmlsitemap_node\xmlsitemap_node.module).
Notice: Undefined index: nid in xmlsitemap_node_form_node_form_alter() (line 136 of D:\xampp\htdocs\standardweb\sites\all\modules\contrib\xmlsitemap\xmlsitemap_node\xmlsitemap_node.module).
Notice: Undefined index: #node in i18n_menu_form_node_form_alter() (line 663 of D:\xampp\htdocs\standardweb\sites\all\modules\contrib\i18n\i18n_menu\i18n_menu.module).
Notice: Undefined index: #node in i18n_menu_form_node_form_alter() (line 664 of D:\xampp\htdocs\standardweb\sites\all\modules\contrib\i18n\i18n_menu\i18n_menu.module).
Notice: Trying to get property of non-object in i18n_menu_form_node_form_alter() (line 664 of D:\xampp\htdocs\standardweb\sites\all\modules\contrib\i18n\i18n_menu\i18n_menu.module).
Notice: Trying to get property of non-object in i18n_menu_form_node_form_alter() (line 670 of D:\xampp\htdocs\standardweb\sites\all\modules\contrib\i18n\i18n_menu\i18n_menu.module).
Notice: Undefined index: #node in _i18n_node_form_node_form_alter() (line 445 of D:\xampp\htdocs\standardweb\sites\all\modules\contrib\i18n\i18n_node\i18n_node.module).
Notice: Trying to get property of non-object in _i18n_node_form_node_form_alter() (line 465 of D:\xampp\htdocs\standardweb\sites\all\modules\contrib\i18n\i18n_node\i18n_node.module).
Notice: Undefined index: field_guestbookimage in file_ajax_upload() (line 267 of D:\xampp\htdocs\standardweb\modules\file\file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 276 of D:\xampp\htdocs\standardweb\modules\file\file.module).
jide’s picture

Try this :

function MYMODULE_init() {
  if (($_GET['q'] == 'system/ajax' || strstr($_GET['q'], 'file/ajax/')) && preg_match('/^[a-z_]+_node_form/', $_POST['form_id'])) {
    module_load_include('inc', 'node', 'node.pages');
  }
}
jisuo’s picture

Yep, #27 worked. :) Nice job.

jurasjo’s picture

@jide ROCKS !!!!!!!!! #27 worksssssss

jide’s picture

Hehe, thanks :)

The bug should be corrected following @sun advices though (although we should find a more generic way to include all needed files like those needed for file upload e.g.).

DanChadwick’s picture

#27 worked for my very general way: all I have is a file field added to regular user-defined content type. I'm *not* using Form Block. The bug occurs when adding a new node of that content type and trying to upload. Save the node without uploading, and for some reason you can edit the node and upload even without #27.

(Note, the node is being created from a custom menu item, which I think is the source of the issue.)

Thanks much, but it seems this is a pretty general issue between the core field field upload ajax and the node form.

chike’s picture

Thanks jide, #27 worked. It's a great relief.

thomasreid’s picture

I had this problem so I used jide's solution in #27. The file now uploads when one clicks "Upload" but when you submit the form now, a custom submit handler I have does not get called. The submit handler does get called though if you select a file but don't click "Upload." I believe this is related to the AJAX callback so any solution?

jdflorez’s picture

#27 works just perfect for me: I'm loading a form block in a lightbox for anonymous users to create content and works just fine.

Thanks jide.

peem83’s picture

unfortunetely #27 does not work if you have formblock on another node add/edit page which contain file field, any ideas how to solve that ?

jgraham’s picture

Status: Active » Needs review
FileSize
556 bytes

Attached patch addresses the issue by calling form_load_include() in the event that we have a node form without the necessary 'modules/node/node.pages.inc' already included following sun's recommended approach in 17/19.

cjgriffin’s picture

#36 worked for me, with a node form on the Dashboard. Thanks jgraham!

deadtech@gmail.com’s picture

#36 worked! thanks.

kreatIL’s picture

#36 worked for me, with Adress field. Thx.

rickharington’s picture

@jdflorez can you pleassde tellme how you got a form block in a lughtbox, it's exactly what I'm looking for.

jon_skilling@hotmail.com’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for this. Worked perfectly!

Peter Majmesku’s picture

#27 works for me, too. how about patching the dev-version with this?

mikey_p’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jbrauer’s picture

ishwar’s picture

Correct ...

#27 is working for me.