我試圖在面板中包含一個模塊窗體,我試過使用drupal_get_form(),但不確定我是否正確使用它。drupal問題 - 如何從另一個模塊打印表單?
在有機基團模塊,有來呈現og_broadcast_form的功能。這就是所謂的一個page_callback內og.module:
// Broadcast tab on group node.
$items['node/%node/broadcast'] = array(
'title' => 'Broadcast',
'page callback' => 'drupal_get_form',
'page arguments' => array('og_broadcast_form', 1),
'access callback' => 'og_broadcast_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'file' => 'og.pages.inc',
'weight' => 7
);
而在og.pages.inc,功能:
function og_broadcast_form($form_state, $node) {
drupal_set_title(t('Send message to %group', array('%group' => $node->title)));
if (!empty($form_state['post'])) {
drupal_set_message(t('Your message will be sent to all members of this group.'));
}
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#size' => 70,
'#maxlength' => 250,
'#description' => t('Enter a subject for your message.'),
'#required' => TRUE,
);
$form['body'] = array(
'#type' => 'textarea',
'#title' => t('Body'),
'#rows' => 5,
'#cols' => 90,
'#description' => t('Enter a body for your message.'),
'#required' => TRUE
);
$form['send'] = array('#type' => 'submit', '#value' => t('Send message'));
$form['gid'] = array('#type' => 'value', '#value' => $node->nid);
return $form;
}
我已經嘗試了數drupal_get_form的變化:
print drupal_get_form('og_broadcast_form', NULL, arg(1)); //where arg 1 is the node id from the url
print drupal_get_form('og_broadcast_form');
print drupal_get_form('og_broadcast_form', &$form_state, arg(1));
print drupal_get_form('og_broadcast_form', $n); //where $n is node_load(arg(1));
print drupal_get_form('og_broadcast_form', &$form_state, $n);
等等,等等......有沒有辦法來完成我想在這裏做什麼?
謝謝,但我也嘗試過......這是我列出的第二個,它根本沒有渲染窗體? – Dashiell0415 2010-07-20 23:01:48
這是不正確的; 'drupal_get_form()'確實接受多個參數。請參閱參數說明,其中報告「...任何其他參數都傳遞給由drupal_get_form()調用的函數,包括唯一窗體構造函數。例如,node_edit窗體要求在此傳遞一個節點對象當它被調用時「。緊接在參數'$ form_id'的描述之後。 – kiamlaluno 2010-07-25 14:12:48
爲什麼不把它作爲參數列表的一部分呢?飛向我。 – Kevin 2010-07-25 14:37:48