[pmwiki-users] captcha & newgroupbox
adam overton
a at plus1plus1plus.org
Mon Apr 28 03:44:35 CDT 2008
cool - well, it took me what felt like forever and a day to figure
out, but i finally have a working version of NewGroupBox with Captcha
implemented inside.... thanks Hans for the tip!
adam
. . .
function NewGroupBox($pagename, $opt) {
global $ScriptUrl,
/* ao - added captcha global vars */
$EnablePostCaptchaRequired, $CaptchaKey, $CaptchaName;
$CaptchaImage = CaptchaImage($pagename); // ao - call captcha image
func - must call this here in order for $CaptchaKey to get loaded
with a value
$defaults = array(
#'size' => '30',
'label' => FmtPageName(' $[Create a new group called:] ', $pagename),
'button' => 'left',
);
$opt = array_merge($defaults, ParseArgs($opt));
$buttonHTML = " <input class='inputbutton newpagebutton'
type='submit' value='{$opt['label']}' /> \n";
$onfocusHTML = "
onfocus=\"if(this.value=='{$opt['value']}') {this.value=''}\"
onblur=\"if(this.value=='') {this.value='{$opt['value']}'}\" ";
$out = "\n <form class='newgroup' action='$PageUrl' method='post'>
<input type='hidden' name='n' value='$pagename' />
<input type='hidden' name='action' value='newgroup' /> \n".
($opt['value'] ? " <input type='hidden' name='value' value='{$opt
['value']}' /> \n" : "").
($opt['focus'] ? " <input type='hidden' name='focus' value='{$opt
['focus']}' /> \n" : "").
($opt['base'] ? " <input type='hidden' name='base' value='{$opt
['base']}' /> \n" : "").
($opt['save'] ? " <input type='hidden' name='save' value='{$opt
['save']}' /> \n" : "").
($opt['autogroup'] ? " <input type='hidden' name='autogroup'
value='{$opt['autogroup']}' /> \n" : "").
($opt['template'] ? " <input type='hidden' name='template'
value='{$opt['template']}' /> \n" : "").
($opt['autopages'] ? " <input type='hidden' name='autopages'
value='{$opt['autopages']}' /> \n" : "").
($opt['button']=="left" ? $buttonHTML : "").
" <input class='inputbox newpagetext' type='text' name='name'
value='{$opt['value']}' size='{$opt['size']}'" .
($opt['focus']=="true" ? $onfocusHTML : "").
"/> \n" .
($opt['button']=="right" ? $buttonHTML : "").
/* ao - captcha markup */
($EnablePostCaptchaRequired==1 ? "<br /><input type='hidden'
name='captchakey' value='{$CaptchaKey}' />
Enter code: <em class='access'>".$CaptchaImage."</em> <input
type='text' name='{$CaptchaName}' size='5' class='inputbox' /> " : "").
" </form>";
return Keep($out);
}
# handles action=new, i.e. what the form sends, sends new page to edit
function HandleNewGroup($pagename) {
global $Author, $EnableAutoGroupPages, $AutoGroupPagesFmt,
$EnablePostCaptchaRequired, /* ao - captcha global var */
$EnablePostRecentChangesForAutoGroupPages, $EnableAutoSave;
// ao -- CAPTCHA REDIRECT IF CODE FAILS //
if($EnablePostCaptchaRequired AND !IsCaptcha()) Redirect
($pagename); // stay on page
//if($EnablePostCaptchaRequired AND !IsCaptcha()) Redirect('{*
$Group}.CaptchaFailed'); // go to failure page
(..... and then the rest of the recipe i've left unchanged)
On 27 Apr 2008, at 1:41 AM, Hans wrote:
> Sunday, April 27, 2008, 9:11:46 AM, adam overton wrote:
>
>> i've got captcha working great with foxcommentbox, so i think my
>> settings are correct. right now, the captcha shows up on the page,
>> but even if no captcha is entered, a new page or new group still gets
>> created. i get the feeling that since the submit button is embedded
>> inside newpageboxplus & newgroupbox, that maybe the form is starting
>> & ending too soon for the captcha to come into play(??)
>
> You would need to change newpageboxplus.php similar as it is done in
> commentboxplus.php, so the captcha fields are added to the form.
>
> Add something like the following ca. line 60
>
> (isset($EnablePostCaptchaRequired) ? "<input type='hidden'
> name='captchakey' value='\$CaptchaKey' />
> Enter code: <em class='access'>\$Captcha </em><input
> type='text' name='\$CaptchaName' size='5' class='inputbox' /> " : "").
>
>
>
> ~Hans
>
More information about the pmwiki-users
mailing list