为了使用 Joomla ReCaptcha 插件 -
1) 从http://www.google.com/recaptcha获取 recaptcha 密钥
2)将这些键设置为recaptcha插件,如果不是则激活它。
3) 前往 Global Configuration=>Site=>Default Captcha
并设置"Default Captcha"=>"Captcha - ReCaptcha"
4)创建具有您的验证码字段的xml表单实例
$form =& JForm::getInstance('myform','path/to/form/form.xml');
5)在表单内创建字段-
$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)提交表单后验证表单-
$post = JRequest::get('post');
jimport( 'joomla.form.form' );
$form =& JForm::getInstance('myform','path/to/form/form.xml');
$res = $form->validate($post);
XML 表单示例 -
<?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>
你也可以试试这个——
如何在我的自定义模块中使用 joomla recaptcha 插件