Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
i am trying to open node edit form in modal window. here is the code i am using
function test_menu() {
$items['test'] = array(
'title' => 'Test Modal',
'page callback' => 'test_page',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
$items['test/%ctools_js/test'] = array(
'title' => 'Test Content Type',
'page callback' => 'modal_content',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function test_page() {
global $user;
ctools_include('ajax');
ctools_include('modal');
ctools_modal_add_js();
$output = ctools_modal_text_button(t('Modal Content'), 'test/nojs/call', 'test');
return array('markup' => array('#markup' => $output));
}
function modal_content($js = FALSE) {
ctools_include('node.pages', 'node', '');
if (!$js) {
return drupal_get_form('test_node_form');
}
ctools_include('modal');
ctools_include('ajax');
$form_state = array(
'title' => t('Add Notification'),
'ajax' => TRUE,
);
$output = ctools_modal_form_wrapper('test_node_form', $form_state);
if (!empty($form_state['executed'])) {
}
print ajax_render($output);
exit;
}
i get the error "Fatal error: Cannot access empty property in field.attach.inc on line 197"
Comments
Comment #1
Letharion CreditAttribution: Letharion commentedCan you try and reduce the code base a bit and determine which line causes the error message?
That will make it much easier for the maintainer to help you.
Comment #2
Deepakml CreditAttribution: Deepakml commentedThanks Letharion,
i think i found what the problem was, to load a content type we need to pass $form_state['build_info']['args'] in ctools_modal_form_wrapper(it calls drupal_build_form) and in drupal_get_form() pass it as 2nd argument. i made the following changes and it is working for me now.
Comment #3
Letharion CreditAttribution: Letharion commentedI'm glad you got it working :)
Comment #5
netentropy CreditAttribution: netentropy commentedWas this for Drupa 7? Would you mind sharing what finally worked?
Comment #6
Deepakml CreditAttribution: Deepakml commentedyes i am using d7.
add
after
hope that works
Deepak
Comment #7
netentropy CreditAttribution: netentropy commentedThanks for responding. For some reason it isn't working , it just does the ajax loading spin thing. I will keep working on it.
Comment #8
netentropy CreditAttribution: netentropy commentedI have tried mimicking your code. Can you see anything out of place?
Comment #9
netentropy CreditAttribution: netentropy commentedI finally got this nearly working. However submitting the form does not save the node. It does for you? New code:
Comment #10
APolitsin CreditAttribution: APolitsin commented***
Comment #11
APolitsin CreditAttribution: APolitsin commentedComment #12
marcel66 CreditAttribution: marcel66 commentedHello all
I have figured out that your code works well (except of some urls: in hook_menu is mentioned 'test/%ctools_js/test' and in link 'test/nojs/call' - they have to be the same.)
BUT... when you have a test node with an image field... and you want to load a new image ... you'll get an error... => ajax problems with form with ajax fields <-> ctools
Comment #13
marcel66 CreditAttribution: marcel66 commentedComment #14
mkadin CreditAttribution: mkadin commentedConfirmed #12, using the image field on the standard "article" node/add form works if you just hit save without uploading first. But if you use the AJAX "upload" button, you get the following error below. Hitting save brings the form up again, this time with the image thumbnail showing - the image has been successfully uploaded. Hitting save again actually saves the form.
Here's the error:
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 /Applications/MAMP/htdocs/drupal-7.10/includes/form.inc).
Notice: Undefined index: #node in comment_form_node_form_alter() (line 1193 of /Applications/MAMP/htdocs/drupal-7.10/modules/comment/comment.module).
Notice: Trying to get property of non-object in comment_form_node_form_alter() (line 1210 of /Applications/MAMP/htdocs/drupal-7.10/modules/comment/comment.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 612 of /Applications/MAMP/htdocs/drupal-7.10/modules/menu/menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 612 of /Applications/MAMP/htdocs/drupal-7.10/modules/menu/menu.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 613 of /Applications/MAMP/htdocs/drupal-7.10/modules/menu/menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 613 of /Applications/MAMP/htdocs/drupal-7.10/modules/menu/menu.module).
Notice: Undefined index: #node in auto_nodetitle_form_node_form_alter() (line 29 of /Applications/MAMP/htdocs/drupal-7.10/sites/all/modules/auto_nodetitle/auto_nodetitle.module).
Notice: Trying to get property of non-object in auto_nodetitle_form_node_form_alter() (line 29 of /Applications/MAMP/htdocs/drupal-7.10/sites/all/modules/auto_nodetitle/auto_nodetitle.module).
Notice: Undefined index: #node in auto_nodetitle_form_node_form_alter() (line 36 of /Applications/MAMP/htdocs/drupal-7.10/sites/all/modules/auto_nodetitle/auto_nodetitle.module).
Notice: Trying to get property of non-object in auto_nodetitle_form_node_form_alter() (line 36 of /Applications/MAMP/htdocs/drupal-7.10/sites/all/modules/auto_nodetitle/auto_nodetitle.module).
Notice: Undefined index: field_image in file_ajax_upload() (line 267 of /Applications/MAMP/htdocs/drupal-7.10/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 276 of /Applications/MAMP/htdocs/drupal-7.10/modules/file/file.module).
Comment #15
thetoast CreditAttribution: thetoast commentedI've come across the same error as above, trying to figure out how it could be fixed because hitting the upload button causes the form to submit which is when the error occurs. My entity reference auto complete fields don't work in ctools modal either but I don't get any errors, basically it looks like anything that uses ajax isn't working. Also, I've noticed if you use jquery ui dialog (in drupal 7 core) you can display a node add page (calling node/add/*) which means you're not calling the node form directly which ultimately means ajax widget fields work fine. Dialog api seems to suffer from the same issue with image uploads, see here
Comment #16
eO_Ae CreditAttribution: eO_Ae commentedI am getting this error, but only on my production environment.
Everything is working fine locally. Its some sort of environmental difference, but I don't even have a clue what its getting hung up on.
Comment #17
nagiek CreditAttribution: nagiek commentedMake sure you include all the JS in your form by calling
Comment #18
bachbach CreditAttribution: bachbach commentedhi, thanks for these samples!
i'm trying to replicate this, but i can't make it work.
i always have php memory errors
[Sat Mar 10 23:54:59 2012] [error] [client 127.0.0.1] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 40961 bytes) in /users/bachir/Sites/domain.org/includes/theme.inc on line 1400, referer: http://dev.domain.org/en/node/454/edit?destination=admin/content/nodes
always with theme.inc on line 1400
as far as i was able to go, it's happend on $output = drupal_render($output); L226 ctools_modal_form_render() of modal.inc
my code is exactly #11
i tried with a minimum test node type (only title field), it's the same
i'm working localy with 256M php memory
drupal 7.12
ctools 7.x-1.0-rc1
any clue ?
Comment #19
bachbach CreditAttribution: bachbach commentedprocess go through this line
L5727 from /includes/common.inc
as info, i'm trying to open a node create form in ctools modale from an other node edit form … maybe some recursions here ?
Comment #20
bachbach CreditAttribution: bachbach commentedOK got it !
this is some incompatibilty with Node form columns module, if i disable it, all works fine
opened an issue here : http://drupal.org/node/1479264
i will check that !
Comment #21
arisaves CreditAttribution: arisaves commentedWhere does one place the code in #11?
Comment #22
nguyentran CreditAttribution: nguyentran commentedHello bachbach,
I can not solve the 200 error, have you solved this, please help. Thanks
Comment #23
jamuy CreditAttribution: jamuy commentedbachbach, en tu codigo #18
Fiajte que no inlcuyes el fomulario si es
drupal_get_form($type . '_node_form', $node);
$form_state['build_info']['args'] = array($node);
Comment #24
jurveen CreditAttribution: jurveen commented+1
I'll tried all the above code for a node add/edit form, unfortunately with no success. It results in a 200 error and a dump of the form array.
Also tried this code here: https://gist.github.com/1979037 See the code below. Same result.
I use Drupal 7.14, CTools 1.0.
I keep on trying to find a solution. Any suggestions?
Comment #25
mkadin CreditAttribution: mkadin commented@jurveen Try adding this line anywhere inside your form alter:
Comment #26
jurveen CreditAttribution: jurveen commentedHi mkadin, thanks for your suggestion. No luck so far.
Isn't ctools_include('node.pages', 'node', ''); supposed to do the same?
Comment #27
jurveen CreditAttribution: jurveen commentedOkay, I got it working! Now, the modal shows the node form with either
ctools_include('node.pages', 'node', '')
orform_load_include($form_state, 'inc', 'node', 'node.pages')
.It seems that the error came from the content type itself. I recreated the content type with exactly the same fields, and now it's working fine. I flushed all caches etc. etc. When I use ctools_modal_form_wrapper() with the old content type, the error reappears! Did anyone have similar experiences, or am I just going crazy?? :(
Comment #28
jernej.c CreditAttribution: jernej.c commentedSorry guys, this is a stupid question, but I'm brand new to Drupal. What do I do with the code above? :o
Thanks for any kinda help in advance.
Jernej
Comment #29
jernej.c CreditAttribution: jernej.c commentedOk, I created a module and enabled it ( I hope this is meant to be a module :P ), but what now? How do I add the links?
Comment #30
drupaledmonk CreditAttribution: drupaledmonk commentedHas anyone been able to fix #14
Comment #31
mkadin CreditAttribution: mkadin commented@drupaledmonk, I believe I was able to solve that problem by adding
In the modal callback
and/or by adding
In a form alter for the form in the modal.
Comment #32
havran CreditAttribution: havran commentedI work with code from #11 but i get AJAX error dump. If i comment out this part
whole node creation process work as expected (form show modal, submit work and node is saved). I debug $js value and i get 0.
Comment #33
havran CreditAttribution: havran commentedMy fault. I use in url 'no_js' and there need to by 'nojs'! This is replaced by 'ajax' in post... Now all working correctly. Here is complete solution for all existing node types (node/add and node/%/edit) http://drupal.stackexchange.com/a/45150/10664.
Comment #34
ashish.verma85 CreditAttribution: ashish.verma85 commentedThese modules can help.
https://www.drupal.org/project/ctools_automodal
https://www.drupal.org/project/ctools_automodal_admin
Comment #35
tarasikarius CreditAttribution: tarasikarius commentedHi guys. I added node ADD form in ctools modal window and ctools autosubmit functionality .
So far so good, but my goal is to return node EDIT form when autosubmit triggered.
Now modal callback function looks like this:
I tryed to add different varians of this:
but it doesn`t work(
Any advice?
Comment #36
shobhit_juyal CreditAttribution: shobhit_juyal commented#11 Perfect thanks.
Comment #37
m.attar CreditAttribution: m.attar commentedUse this module: https://www.drupal.org/project/modal
Comment #38
MustangGB CreditAttribution: MustangGB commented