我需要在内容类型 A 的视图(而不是编辑)中创建一个表单。
此表单需要将数据提交到内容类型 B。
我注意到 node/ 是表单的“操作”,可让您编辑节点。但是,如果我在 A 上的表单中添加相同的操作,它会显示 B 的编辑节点页面。
我的表单很简单:
<form action="xxx">
<input type="text" name="cck_field_to_be_added_in_B" value="foobar">
</form>
设置 xxx 操作还不够,因为 FAPI 需要 form_id 和其他内容...所以,我怎样才能构建一个“正确”的表单并以正确的方式发送数据?
有什么想法吗?
----编辑----
使用它有效的 rimian 解决方案。详细信息如下:
我需要使用 CCK 创建的节点视图中的表单。所以我的模块有两个功能:
function getForm(){
return drupal_get_form('buildForm');
}
function buildIngredientsForm(){
$form[]... //bla bla bla build the form
return $form;
}
因为我希望它位于 cck 内容中,所以我可以“破解”CCK 的主题系统。这里解释一下如何: http://drupal.org/node/206980
现在,每当您想要显示您的表单只需调用 print mymodule.getForm();
,魔法就完成了。
问候,
塞戈拉斯
I need to create a form in the view (not in the edit) of a content type A.
This form need to submit the data to a content type B.
I notice that node/<nodeID/edit
is the "action" of the form which let you edit a node. But if I put the same action in my form on A it shows me the editing node page of B.
My form is as simple as:
<form action="xxx">
<input type="text" name="cck_field_to_be_added_in_B" value="foobar">
</form>
Setting the xxx action isn't enough, because the FAPI requires form_id and other stuff... So, How can I build a form which is "correct" and sends the data in the rigth way?
Any idea?
----EDIT----
Using the rimian solution it worked. Heres are the dettails:
I needed the form in the view of a node created with CCK. So I have my module with two functions:
function getForm(){
return drupal_get_form('buildForm');
}
function buildIngredientsForm(){
$form[]... //bla bla bla build the form
return $form;
}
Because I want this inside a cck content, than I can "hack" the theming system of CCK. Here explain how: http://drupal.org/node/206980
Now, whenever you wats to display your form just call print mymodule.getForm();
and the magic is done.
Regards,
Segolas
发布评论
评论(1)
将另一个回调添加到提交节点的编辑表单时调用的函数数组中。您需要了解表单 API 的基础知识。这并不太难。
它是这样的:
然后..
参见:
http://api.drupal.org/api/drupal/包括--form.inc/group/form_api
http://drupal.org/project/examples
Add another callback to the array of functions that are called when the node's edit form is submitted. You'll need to understand the basics of the form API. It's not too hard.
It goes something like this:
Then..
See:
http://api.drupal.org/api/drupal/includes--form.inc/group/form_api
http://drupal.org/project/examples