2

私はそのようなファイルを持っています:

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'));
}

?>

helper.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;

  }
}
?>

および 2 つのテンプレート: 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

メール設定でOK

4

3 に答える 3

0

ふりをして動作するコードは次のとおりです。

helper.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>
于 2013-11-16T19:43:22.490 に答える
0

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

フォームで、action 属性を削除します。

<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');

それが役に立てば幸い

于 2013-11-14T22:20:19.147 に答える