Using ReCaptcha with my custom form in Joomla

不打扰是莪最后的温柔 提交于 2019-12-30 07:08:08

问题


I'm trying to use JFormFieldCaptcha to work on my custom jForm. I managed to get the job done with registration and contact forms. However i want to build my own contact form which is based on an XML file somehow look like this:

<form>
    <fieldset addfieldpath="<path to JFormFieldCaptcha class>">
        <field 
             name="captcha" label="Captcha" description="COM_DEZTOUR_ORDER_CAPTCHA_DESC"
         type="text" validate="captcha"
        />
     </fieldset>
</form>

i cannot figure out why this code not working. Any help would be appriciated!


回答1:


In order to use Joomla ReCaptcha plugin -

1)Get recaptcha keys from http://www.google.com/recaptcha

2)Set these keys to recaptcha plugin and activate it if it's not.

3) Go to Global Configuration=>Site=>Default Captcha

and set "Default Captcha"=>"Captcha - ReCaptcha"

4)Create xml form instance which has your captcha field

$form   =& JForm::getInstance('myform','path/to/form/form.xml');

5)Create fields inside form-

$fieldSets = $form->getFieldsets();
foreach ($fieldSets as $name => $fieldSet) :
?>          
    <?php
    foreach ($form->getFieldset($name) as $field):
    ?>
        <p>
        <?php if (!$field->hidden) : ?>
        <span class="formlabel"><?php echo $field->label; ?></span> 
        <?php endif; ?>
        <span class="control"><?php echo $field->input; ?></span>
        </p>
    <?php
    endforeach;
    ?>          
    <div class="clr"></div>
<?php
endforeach;             

6)After form submission validate form-

$post   = JRequest::get('post');
jimport( 'joomla.form.form' );
$form   =& JForm::getInstance('myform','path/to/form/form.xml');
$res    = $form->validate($post);

XML form example-

<?xml version="1.0" encoding="utf-8"?>
<form
    addfieldpath="/administrator/components/com_franchise/models/fields">
    <fieldset name="information">        
         <field id="name"
            name="name"
            type="text"
            label="Name"
            description=""
            class="inputbox"
            size="30"
            default=""
            required="true"
        />  

         <field
            name="captcha"
            type="captcha"
            label="COM_CONTACT_CAPTCHA_LABEL"
            description="COM_CONTACT_CAPTCHA_DESC"
            validate="captcha"

        />

    </fieldset> 
</form>

You can also try this- How to use joomla recaptcha plugin to my custom Module



来源:https://stackoverflow.com/questions/12894134/using-recaptcha-with-my-custom-form-in-joomla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!