我有这样的文件:
mod_get_price.php:
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
require_once('helper.php');
JHTML::stylesheet('styles.css','modules/mod_get_price/css/');
$form_send = JRequest::getVar('form_send', 'notsend');
switch($form_send){
case 'send':
$your_name = JRequest::getVar('your_name', 'No name');
$your_question = JRequest::getVar('your_question', 'No question');
$send = ModLittleContactHelper::SendMail($your_name,
$your_question);
if ( $send !== true ) {
echo 'Error sending email: ' . $send->message;
}
require(JModuleHelper::getLayoutPath('mod_get_price', 'sendok_tmpl'));
break;
default:
require(JModuleHelper::getLayoutPath('mod_get_price', 'default_tmpl'));
}
?>
助手.php:
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
class ModLittleContactHelper{
public function SendMail($your_name, $your_question){
$config = JFactory::getConfig();
$mail = JFactory::getMailer();
$sender = array($config->get( 'config.mailfrom' ), $config->get( 'config.fromname' ));
$mail->setSender($sender);
$mail->setSubject('Сообщение с сайта');
$mail->addRecipient('info@dmgroup.su');
$body = "Вопрос с сайта<br/>";
$body.= "-------------------------<br/>";
$body.= "Пользователь: ".$your_name."<br/>";
$body.= "Вопрос: ".$your_question."<br/>";
$mail->setBody($body);
$mail->IsHTML(true);
$send = $mail->Send();
return $send;
}
}
?>
和两个模板:default_tmpl 和 sendok_tmpl
default_tmpl :
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
?>
<div class="right_area">
<h3>ЗАДАТЬ ВОПРОС</h1>
<form action="index.php" method="post" id="sc_form">
<input name="your_question" rows="5" cols="30" placeholder="Ваш вопрос" required></input><br/>
<input name="your_name" rows="5" cols="30" placeholder="Ваш e-mail" type="email" required/><br/>
<input type="submit" name="send" value="Отправить" id="send-button" />
</form>
</div>
当我单击发送按钮时 - 没有任何反应,邮箱也是空的。
我做错了什么,如何编写简单的反馈模块插件?
我使用 3.1 Joomla
模块:https://dl.dropboxusercontent.com/u/59666091/mod_get_price.zip
使用邮件设置一切正常
如果你使用的是Joomla 3+,首先你不应该使用JRequest,这是不推荐使用的。用途:
$input = JFactory::getApplication()->input;
// then use the available JInput methods, but the get() will do the basics
$input->get($name, $default=null, $filter= 'cmd');
// Parameters
// string $name Name of the value to get.
// mixed $default Default value to return if variable does not exist.
// string $filter Filter to apply to the value
在表单中,删除操作属性。
<form method="post" id="sc_form">
<!-- form elements -->
</form>
JInput 使用示例:
你有:
$form_send = JRequest::getVar('form_send', 'notsend');
只需更改:
$input = JFactory::getApplication()->input; // only once on each method
// it will look as
$form_send = $input->get('form_send', 'notsend');
希望对你有帮助
我怀疑你的模块代码正在调用,因为-
1)您正在使用模块,因此为了调用模块,如果没有为所有页面设置项 ID,您还需要传递项目 ID。
2)根据代码,case 'send'
永远不会调用。所以你可以试试这个——
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
$jinput = JFactory::getApplication()->input;
$Itemid= $jinput->get('Itemid', '', 'INT');
?>
<div class="right_area">
<h3>ЗАДАТЬ ВОПРОС</h1>
<form action="index.php" method="post" id="sc_form">
<input name="your_question" rows="5" cols="30" placeholder="Ваш вопрос" required></input><br/>
<input name="your_name" rows="5" cols="30" placeholder="Ваш e-mail" type="email" required/><br/>
<input type="submit" name="send" value="Отправить" id="send-button" />
<input type="hidden" name="Itemid" value="<?php echo $Itemid?>"/>
<input type="hidden" name="form_send" value="send" />
</form>
</div>
以下是可以假装工作的代码:
助手.php
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
/**
* Class ModLittleContactHelper
*/
class ModLittleContactHelper
{
/**
* @param $your_name
* @param $your_question
*
* @return mixed
*/
public static function SendMail($your_name, $your_question)
{
jimport('joomla.mail.mail');
// ensure that we have the security from the form token
JSession::checkToken() or die('Invalid Token');
$config = JFactory::getConfig();
$mail = JFactory::getMailer();
$sender = array($config->get('config.mailfrom'), $config->get('config.fromname'));
$mail->setSender($sender);
$mail->setSubject('Сообщение с сайта');
$mail->addRecipient('info@dmgroup.su');
$body = "Вопрос с сайта<br/>";
$body .= "-------------------------<br/>";
$body .= "Пользователь: " . $your_name . "<br/>";
$body .= "Вопрос: " . $your_question . "<br/>";
$mail->setBody($body);
$mail->IsHTML(true);
$send = $mail->Send();
return $send;
}
}
?>
mod_get_rpice.php:
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
require_once('helper.php');
$input = JFactory::getApplication()->input; // only once on each method
$form_send = $input->get('form_send', 'notsend');
$app = JFactory::getApplication();
switch ($form_send)
{
case 'send':
$your_name = $input->get('your_name', 'No name', 'string');
$your_question = $input->get('your_question', 'No question');
// $app->enqueueMessage("Mail sent", "success"); // Uncomment for debug
$send = ModLittleContactHelper::SendMail($your_name, $your_question);
if($send !== true)
{
echo 'Error sending email.';
}
else
{
echo 'Message successfully sent.';
}
require(JModuleHelper::getLayoutPath('mod_get_price', 'sendok_tmpl'));
break;
default:
// $app->enqueueMessage("Mail Not sent", "error"); // Uncomment for debug
require(JModuleHelper::getLayoutPath('mod_get_price', 'default_tmpl'));
}
?>
/tmpl/default.php
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
?>
<div class="right_area">
<h1>ЗАДАТЬ ВОПРОС</h1>
<form method="post" id="sc_form">
<label for="your_question">Ваш вопрос</label>
<input id="your_question" name="your_question" placeholder="Ваш вопрос" required/><br/>
<label for="your_name">Ваш e-mail</label>
<input id="your_name" name="your_name" placeholder="Ваш e-mail" type="email" required/><br/>
<input type="submit" name="form_send" class="btn btn-primary" value="send" id="send-button"/>
<?php echo JHtml::_('form.token');?>
</form>
</div>