【问题标题】:How to add recaptcha to contact form如何将验证码添加到联系表格
【发布时间】:2015-01-21 10:52:47
【问题描述】:

我尝试使用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>');
}

【问题讨论】:

    标签: php joomla3.0


    【解决方案1】:

    代替

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

    试试

    JRequest::get('post');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-04
      • 2015-10-24
      • 2017-02-13
      • 2017-09-30
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多