Perform the following steps to reproduce the issue
1. Create block
/*
* hook_block_info
*/
function mymodule_block_info() {
$blocks[0] = array(
'info' => t('Node form in block'),
// Cached elsewhere.
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/*
* hook_block_view
*/
function mymodule_block_view($delta = '') {
module_load_include('inc','node','node.pages');
$block['content'] = node_add('page');
return $block;
}
2. Implement form alter and inject ajax element
/*
* hook_form_FORM_ID_alter
*/
function mymodule_form_node_form_alter(&$form, &$form_state, $form_id){
$node = $form['#node'];
$type = $node->type;
//add the calculate button
$form['actions']['btn_calculate']=array('#type'=>'button','#value'=>t('Compute'),
'#ajax'=> array('callback' => 'mymodule_compute',
'wrapper' => "div_output_$type",),
'#weight'=>'49',
);
//add the div to display output of calculation
$form["replace_div_$type"] = array(
'#markup'=>'',
'#prefix' => "<div style='clear:both;' id='div_output_$type'>",
'#suffix' => '</div>',
'#weight'=>'50',
);
}
/*
* implement mymodule_compute
*/
function mymodule_compute($form,&$form_state){
$node = $form['#node'];
$type = $node->type;
$form["replace_div_$type"]['#markup']=t('Hello world');
return $form["replace_div_$type"];
}
3. Add the block to the content region
4. Click on the "Compute" button
The error "Call to undefined function node_form_validate" occurs.
Note: this problem does not occur when the menu node/add/page is called
Comments
Comment #1
rfaysubscribe
Comment #2
dawehnerWhat about creating a wrapper form which loads the node page.
The problem here is when you call ajax the form is build, but the block system is not used at all.
Comment #3
sukr_s commentedThe current work around that i'm using is to load the node.pages.inc on the top level (outside all functions) in the module that defines this block. but i think there should be a better way to do that.
Comment #4
idflood commentedThanks sukr_s, you saved me some time. I too think there should be better way.
by the way, I included this line at the top of my module:
require_once(DRUPAL_ROOT . "/modules/node/node.pages.inc");
Comment #5
inductor commentedSukr_s, thanks for a workaround! The error happens also when you try to put the node add form (with ajax file/image upload widgets) into a block.
Comment #6
wizonesolutionsSubscribe - going to look into this if I get a chance.
Comment #7
eric_a commentedTry form_load_include() in your form alter.
See http://api.drupal.org/api/drupal/includes--form.inc/function/form_load_i...
and
#561226: Forms (elements) need to able to specify include files to be loaded for building
Comment #8
eric_a commentedOr don't use node_add() but call the form directly, after having done a form_load_include().
Comment #9
inductor commentedUnfortunately, form_load_include() doesn`t do the job:
gives the:
error.
Maybe, I`m doing something wrong?
Comment #10
eric_a commented@inductor
You're working with a menu router page callback, two form ID's, mixing up their $form_states. (And to me it looks bizar to have a menu router item get a form and then within the form constructor get another form and return that one...)
This issue is really about making sure that a cached form knows what to include before the processing starts.
The basic idea is something like this:
Comment #11
inductor commentedThanks, Eric_A, your solution in #10 works!
Comment #12
m4oliveiSolution in #10 works for me as well.
I also found the same issue as noted here when using node_page_edit() to render a node edit form. In my case I was using a multi-value node reference field (references module) with an auto-complete textfield, and was getting the error noted when adding fields.
In case anyone would like to see the replacement for a call to node_page_edit():
Thanks!
Comment #13
mdupontSeems like it's fixed.
Comment #15
kurtzhong commentedThis is a very interesting issue, #3 work good for me.
I am so unlucky, #10 doesn't work. I am invoking a node edit form, and when i upload image, if i click `upload`, then it will return `no file input`.
Comment #16
Eugene Fidelin commentedFile uploads doesn't work through AJAX. User must first click "Upload" button and then click "Submit" - in this case when AJAX form is submitted file will be already uploaded previously - and you won't get this bug.
Try this solution if you want to upload files automatically after user selects them http://drupal.stackexchange.com/questions/31121/how-can-i-automatically-...
Comment #17
anybodyThis answer may help you and others:
http://julian.pustkuchen.com/node/702
Comment #18
gangu commentedHello,
On drupal 7, I have a problem with a form. Render content type form in drupal 7 everthing working fine but
I created a Field Collection which appears in the node.
When I click Add another item this error occurs
/************Error************/
An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /system/ajax
StatusText: n/a
ResponseText: ShareEmailFacebookTwitterGoogle+PinterestLinkedInStumbleUponRedditGoogle BookmarksWordPressTumblrDeliciousDiggMySpaceYahoo BookmarksBeboMister-WongApp.netWaneloOrkutXINGBufferEvernoteWhatsAppMendeleyPocketVKPinboardSpringpadFlipboardArtoAIMYahoo MessengerPlurkDiasporaBlogger PostTypePad PostBox.netKindle ItBaiduNetlogCiteULikeJumptagsFunPInstapaperPhoneFavsXerpiNetvouzDiigoBibSonomyBlogMarksStartAidKhabbrMeneameYoolinkBookmarks.frTechnotizieNewsVineFriendFeedProtopage BookmarksBlinklistYiGGWebnewsSegnaloPushaYouMobSlashdotFarkAllvoicesJamespotTwiddlaLinkaGoGoNowPublicLiveJournalLinkatopiaBuddyMarksViadeoWistsSiteJotDZoneCare2 NewsBitty BrowserOdnoklassnikiMail.RuSymbaloo FeedsFolkdNewsTrustAmazon Wish ListPrintFriendlyTuentiEmailRediff MyPageGoogle GmailYahoo MailOutlook.comAOL MailAny email By AddToAny
We Are Working On Riley Drupal
The website encountered an unexpected error. Please try again later.
ReadyState: undefined
/***********************/
function customurl_menu() {
$items = array();
$items['program/%/register'] = array(
'title' => t('Add @node_type', array('@node_type' => t('Node Type'))),
'page callback' => 'drupal_get_form',
'page arguments' => array('module_node_add_form', 'registration'),
'access arguments' => array('administer nodes'),
'file path' => drupal_get_path('module', 'node'),
'file' => 'node.pages.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
return $items;
}
function module_node_add_form ($form, &$form_state, $node_type) {
global $user;
//if( !function_exists("node_form")) {
module_load_include('inc', 'node', 'node.pages');
//}
//if( !function_exists("field_collection_item_form_validate")) {
module_load_include('inc', 'field_collection', 'field_collection.pages');
// }
$node = (object) array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => $node_type,
'language' => LANGUAGE_NONE,
);
node_object_prepare($node);
$form_state['build_info']['args'] = array($node);
form_load_include($form_state, 'inc', 'node', 'node.pages');
$form = drupal_retrieve_form($node_type . '_node_form', $form_state);
drupal_prepare_form($node_type . '_node_form', $form, $form_state);
return $form;
}
Comment #19
ramkris commentedHi,
Please check the below link
https://www.drupal.org/forum/support/post-installation/2013-01-23/call-t...
if(!isset($form_state['build_info']['files'])){
$form_state['build_info']['files'] = array("menu" => "modules/node/node.pages.inc");
}
this solution working fine for me.