joomla 模块开发与表单 - 如何处理 [英] joomla module development with form - how to process
问题描述
我正在创建一个简单的 Joomla 2.5 模块,它将有一个 html 表单.
I'm creating a simple Joomla 2.5 module that will have an html form.
mod_mymodule/tmpl/default.php
:
<form method="post" id="myemailform" action="">
<label for="ReferralName">Enter Name:</label><input type="text" name="name" value="<?php echo modCamcloudReferralHelper::getReferralName(); ?>">
<label for="ReferralEmail">Enter Email Address:</label><input type="text" name="email">
<label for="ReferralMessage">Enter Message (optional):</label><textarea class="message"></textarea>
<span class="countdown"></span>
<button type="submit" value="Send Email">Send Email</button>
<?php echo JHtml::_('form.token'); ?>
</form>
我有一个助手类:
mod_mymodule/helper.php
- 这里面只有一些实用函数.
mod_mymodule/helper.php
- this just has some utility functions in it.
我的问题是这里在服务器端处理我的表单的通常约定是什么.我试图找到人们所做的事情的例子,但我似乎找不到任何东西.难道我只是把所有的东西都放在助手类中:
My question is what is the usual convention here to process my form on the server side. I tried to find examples of what people have done but I can't seem to find anything. Do I just put everything in the helper class:
<form method="post" id="myemailform" action="..helper.php">
或者类似的东西?提前致谢.
Or something like that? Thanks in advance.
推荐答案
是的,你应该在模块助手类中进行表单处理.将任何逻辑排除在模板文件之外,您可以使用 mod_mymodule.php
在包含视图文件之前调用辅助方法并分配变量.
Yes, you should do form processing in module helper class. Keep any logic out of the template file, and you can use mod_mymodule.php
to call helper methods and assign variables before including the view file.
不要设置为表单操作帮助文件!我认为在您的情况下,操作应该是同一页面,因此您也可以省略操作网址.
Do not set as form action helper file! I think in your case action should be the same page, so you can also ommit action url.
根据评论中的要求,这将是您的 mod_mymodule.php
As requested in the comments, this would be the content of your mod_mymodule.php
// include helper file
require_once dirname(__FILE__).'/helper.php';
// call some method of the helper class
$items = modMymoduleHelper::getItems();
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
// render view file from mod_mymodule/tmpl/default.php, $items is available in the view file
require JModuleHelper::getLayoutPath('mod_mymodule', $params->get('layout', 'default'));
这篇关于joomla 模块开发与表单 - 如何处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!