如何将recaptcha添加到联系表单

时间:2015-01-21 10:52:48

标签: php joomla3.0

我尝试使用this question中的方法,但它并不适用于我。 提交表单后,我总是收到此错误:

  

致命错误:无法在contact.php第76行中使用JInput类型的对象作为数组...

第76行看起来像这样:

$res = $dispatcher->trigger('onCheckAnswer',$post['recaptcha_response_field']);

我的联系表格:

<div id="contact">
            <div id="message"></div>

            <form method="post" action="<?php
    echo JURI::root() ?>modules/module/tmpl/form/contact.php" name="contactform" id="contactform">

            <fieldset>

            <input name="name" type="text" id="name" size="30" value="" placeholder="<?php
    echo $params->get('contactname'); ?>" onfocus="this.placeholder = ''" onblur="this.placeholder = '<?php
    echo $params->get('contactname'); ?>'"/>

            <br />
            <textarea style="width: 275px;" name="comments" cols="40" rows="3" id="comments" style="width: 350px;" placeholder="<?php
    echo $params->get('contactcomment'); ?>" onfocus="this.placeholder = ''" onblur="this.placeholder = '<?php
    echo $params->get('contactcomment'); ?>'"></textarea>
            <br />
            <br /> 
            <?php
                JPluginHelper::importPlugin('captcha');
                $dispatcher = JDispatcher::getInstance();
                $dispatcher->trigger('onInit','recaptcha');

            ?>
            <div id="recaptcha"></div>
            <input type="submit" class="submit" id="submit" value="<?php
    echo $params->get('contactbutton'); ?>" />

            </fieldset>

            </form>

            </div>

我将此添加到contact.php

$post = JFactory::getApplication()->input->post;
$dispatcher = JEventDispatcher::getInstance();
JPluginHelper::importPlugin('captcha');
$res = $dispatcher->trigger('onCheckAnswer',$post['recaptcha_response_field']);
if(!$res[0]){
    die('<div class="error_message">' . $errorcomments . '</div>');
}

1 个答案:

答案 0 :(得分:0)

而不是

JFactory::getApplication()->input->post;

尝试

JRequest::get('post');