Reputation: 85
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!
Upvotes: 3
Views: 10908
Reputation: 7059
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
Upvotes: 9