用表单进行joomla模块开发-如何处理 [英] joomla module development with form - how to process
问题描述
我正在创建一个具有html表单的简单Joomla 2.5模块.
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>
我在以下位置有一个帮助者课程:
I have a helper class at:
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屋!