Drupal 6 将变量从表单传递到内容,如何?
我用这个简单的形式创建了一个块(左)。 现在我想在页面(中心)上处理并显示结果 我该怎么办?
输入:
name = James
surname = Bond
我想要的输出:
<div style="color:red">Welcome, James Bond</div>
这是我编写并工作的块。
<?php
echo drupal_get_form('myForm');
function myForm($form_state) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#size' => 20,
'#maxlength' => 10
);
$form['surname'] = array(
'#type' => 'textfield',
'#title' => t('Surname'),
'#size' => 20,
'#maxlength' => 10
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save')
);
return $form;
}
function myForm_submit($form,&$form_state)
{
//??
};
现在我需要显示输出:)。
请不要建议使用 VIEWS 或任何其他插件。
我想从内到外学习Drupal。不是相反;)
I created a BLOCK (left) with this simple form.
Now I want to PROCESS and DISPLAY results on PAGE (center)
How can I do it ?
inputs:
name = James
surname = Bond
output I want :
<div style="color:red">Welcome, James Bond</div>
here is a BLOCK which i wrote and works.
<?php
echo drupal_get_form('myForm');
function myForm($form_state) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#size' => 20,
'#maxlength' => 10
);
$form['surname'] = array(
'#type' => 'textfield',
'#title' => t('Surname'),
'#size' => 20,
'#maxlength' => 10
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save')
);
return $form;
}
function myForm_submit($form,&$form_state)
{
//??
};
Now I need to display the output :).
Please don't suggest to use VIEWS or any other addon.
I want to learn Drupal from Inside out. Not the other way around ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯,这在一定程度上取决于你想如何做事。由于您正在学习如何制作 drupal 模块,因此您可能希望从
$form_state['redirect']
更为合适,正如 Henrik 在他的评论中所解释的那样。有更快的方法可以做到这一点,但是这样做,您将为 drupal 可以缓存的每个搜索结果生成 url,这很好。另外,不依赖于帖子参数,人们可以为搜索结果添加书签
另一件事是,您可能希望对表单进行一些基本验证。这将是一个很好的学习实践。那看起来像这样:
Well, it depends a bit on how you want to do things. Since you are learning how to make a drupal module, you might want to start with an implementation of hook_menu(). This hook is used to define menu items, which basically means that you can register urls with that function. Going that route you can:
$form_state['redirect']
as Henrik explained in his comment.There are quicker ways to do this, but doing it this way, you will generate urls for every search result that drupal can cache, which is nice. Also not being dependent on the post parameters people can bookmark the search results
Another thing is that you might want to put some basic validation to your form. That would be a good practice to learn. That would look something like this:
您可以在表单中实现 AHAH,并指定页面内容区域内的一个元素作为“包装器”(将在其中放置回调函数结果的元素)。但是,在尝试之前,您需要了解欧宝先生的极好的建议。
You could implement AHAH in your form, and specify an element inside your page's content area as the 'wrapper' (the element in which the results of the callback function will be placed). But, you would need to understand the excellent advice of Mr. Opel before you even attempt it.
使用 drupal_set_html_head() 将一串脚本写入页面的 head 部分怎么样?我在特定页面上执行此操作(获取用户纬度和经度并将它们传递到我的 gMap 函数中),但我对直接从 hook_form_submit() 执行相同的操作感兴趣。我已经做了一些尝试,显然我正在输出脚本字符串,但从提交调用该函数似乎不起作用。
How about using drupal_set_html_head() to write a string of script to the head section of the page? I am doing this on specific pages (getting user latitude and longitude and passing them into my gMap function), but I am interested in dong the same thing directly from hook_form_submit(). I have made a few tries at it, and I am obviously outputting the script string but calling the function from submit doesn't seem to work.
如果提交函数创建了一个充满 html 输出的页面;将其传递给页面回调的最佳方法是什么?我怀疑作为 url 上的参数传递是否有效。
我塞进了一个会话变量,但也许有更好的方法?
if the submit function creates a page full of html output; what is the best way to pass this to a page callback? i doubt that passing as an arg on the url would work.
i stuffed into a session var but maybe a better way?