我想知道是否可以在页面中插入节点。我使用Drupal 7,我找不到如何做到这一点。
有人有想法吗?我试着这样做:
function test(){
if (!function_exists('node_add')) {
module_load_include('inc', 'node', 'node.pages');
}
print drupal_render(node_add('node_example'));
}
我的表单显示但很差。这是“我的主题”
答案 0 :(得分:2)
我希望我能正确理解你的问题。我的评论的答案确实有帮助!如果 是您尝试添加到菜单的节点表单,则通常使用Drupal中的hook_menu()函数完成。这里有一些示例代码可以帮助您入门
function YOURMODULE_menu() {
// Here, substitute in the URL of your page. It can be mymodule/add_content or whatever else you'd like
$items['YOUR_PAGE_URL'] = array(
'type' => MENU_CALLBACK,
'title' => t('YOUR PAGE TITLE'),
'page callback' => 'drupal_get_form',
'page arguments' => array('your_node_function'), // Here, you should put in the function that creates your node form
'access arguments' => array('Administer content'), // This is optional, you can require a user to have certain permissions set to access your page/form
);
return($items);
}
请在测试前清除缓存!
正在创建表单的函数中的示例代码:
function your_node_function($form, &$form_state)
{
$form['field_1'] = array(
'#type' => 'textfield',
'#title' => t('Field label'),
'#description' => t('Help user understand what to input here'),
'#required' => TRUE,
);
return $form;
}
看看你是否能看到这个微小的单场形式来帮助你入门。这并没有解释如何实际保存用户数据等,因为这超出了这里单个答案可以提供的范围,但这应该可以帮助您开始使用连接到菜单系统的表单....
我希望这有助于!!!!
===================编辑===================
以下是您可以添加到Drupal中表单的不同类型表单元素的在线文档:http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7