By following examples online and help from the community I am able to put a node form in a modal window but it fails when I attempt to save it.
I cannot figure out what I am missing. The code follows:
$type= 'test';
//module_load_include('inc', 'node', 'node.pages');
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,
);
$node = (object) array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => LANGUAGE_NONE);
drupal_get_form($type . '_node_form', $node);
$form_state['build_info']['args'] = array($node);
$output = ctools_modal_form_wrapper('test_node_form', $form_state);
if (!empty($form_state['executed'])) {
};
print ajax_render($output);
exit;
}
Comments
Comment #1
jordanmagnuson commentedEver get this figured out? I'm experiencing something similar in that my form's submit function is not being called when in modal...
Comment #2
couturier commentedIf a solution ever presents itself, I think a lot of people are going to be interested. Lots of questions have been filed over this type of functionality with CTools modals in the forums and issue queues. See ongoing work here: http://drupal.org/node/828794#comment-5518224
Comment #3
Ashlar commentedThis support request has not been active for over two months. In an effort to clean-up the issue queue this item has been closed. If all modules are up-dated and the request is still a concern please feel free to change the Status back to active.
Comment #4
Ashlar commentedComment #5
Equinger commentedI have the same issue. My submit handlers are not getting called, and for some reason the nodes are not being submitted with default form submission.
Comment #6
Equinger commentedOk, here's the issue: you need to run $node = node_submit($form_state['values']) followed by a node_save($node) in a submit handler. I was wrong, my submit handler was getting called, I am guessing that the default submit handler that is used by ctools has no way of knowing that this form is a node form. I feel like that should be corrected.
Pardon my whining, but:
1)The community should have been able to answer that question better since this was posted just less than a year ago. This should be a pretty generic question. I Googled for hours. My only explanation is that Drupal developers are getting further away from foundations ... or the ones who do know what they're doing deemed this trivial ... which is fair I suppose.
2) I get the sense that with Drupal, it's easy to frame problems incorrectly ... the more behind the scenes magic that we allow to go on.... It gets us all thinking in a really roundabout way (rube golberg style ...), when these things should really be simple. This is what frustrates me the most with Drupal.
Comment #7
couturier commentedWhen I think of the magnitude of what I've been given in the basic Drupal platform, which has been given to us for free by Dries Buytaert's choice of a General Public License, I have an overwhelming sense of gratefulness. Modals are a complex functionality not included in the basic platform. I've benefitted from putting desired complexities on a "holding" wish list until they are better developed, which could be years. Of course it would be nice to have a more straightforward answer for modals problems, but hang in there. In time it should come.
I've recently been intrigued by several sites that seem to open a small pop-up window through the Google Chrome and IE browsers themselves. If we had something like a target="_blank" attribute, only to open a smaller window, it would be great. That's out of the control of Drupal programming, however, and in the hands of HTML standards.
For an example of what I'm talking about, see this site with a Flash presentation: http://dkdisplaycorp.com and then click on the logos within the rotating pictures. I'm not enough of a programmer to understand how they are getting new pop-up windows with the vendors' websites.
Comment #8
merlinofchaos commentedThat seems like it would require magic to know anything about that.
Node forms are very complicated. What you're doing is not a common task. Modals and javascript are complicated. Putting it all together can be tough. And to be honest, not that many people really are able to provide support in the CTools queue. Maybe stackoverflow would've gotten you more eyeballs.
Yes, everything should be simple, but when you start breaking things down into components, what seems simple really isn't.
I'm sorry you were so frustrated with this, though. Things are made tougher by the difficulty of documenting FAPI and the fact that node forms are a pretty difficult implementation of FAPI due to history.