如何将验证码添加到联系表单


How to add recaptcha to contact form

我尝试使用这个问题中的方法,但它对我不起作用。提交表单后我总是收到此错误:

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

第 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>

我将此添加到联系人中.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>');
}

而不是

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

尝试

JRequest::get('post');