Login   Register  
PHP Classes
elePHPant
Icontem

File: test_recaptcha_input.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Manuel Lemos  >  Forms generation and validation  >  test_recaptcha_input.php  >  Download  
File: test_recaptcha_input.php
Role: Example script
Content type: text/plain
Description: Example to demonstrate how to use the reCAPTCHA custom input
Class: Forms generation and validation
HTML forms generation and validation.
Author: By
Last change:
Date: 1 year ago
Size: 3,120 bytes
 

Contents

Class file image Download
<?php
/*
 *
 * @(#) $Id: test_recaptcha_input.php,v 1.2 2013/01/01 10:32:54 mlemos Exp $
 *
 */

    
require('forms.php');
    require(
'http.php');
    require(
'form_recaptcha.php');

    
$key ''$line __LINE__;
    
$private_key '';
    if(
strlen($key) == 0)
        die(
'Please go to the Recaptcha site '.
        
'https://www.google.com/recaptcha/admin/create to obtain the public '.
        
'and private keys to set in the line '.$line.'.');
    
$form = new form_class;
    
$form->NAME 'captcha_form';
    
$form->METHOD 'GET';
    
$form->ACTION '';
    
$form->debug 'error_log';
    
$error $form->AddInput(array(
        
'TYPE'=>'custom',
        
'ID'=>'captcha',
        
'LABEL'=>'<u>E</u>nter the following text:',
        
'ACCESSKEY'=>'E',
        
'CustomClass'=>'form_recaptcha_class',
        
'Key'=>$key,
        
'PrivateKey'=>$private_key,
        
// 'ValidationErrorMessage'=>'It was not entered the correct text.',
        // 'DependentValidation'=>'',
        // 'InputClass'=>'',
        // 'InputStyle'=>'',
        // 'InputTabIndex'=>10,
        // 'InputExtraAttributes'=>array(),
        /* 'Format'=>'<div>{image}</div>
         <div>{instructions_visual}{instructions_audio} {input}</div>
         <div>{refresh_btn} {visual_challenge}{audio_challenge} {help_btn}</div>',*/
        /* 'Text'=>array(
            'instructions_visual'=>'Enter the words above',
            'instructions_audio'=>'Enter the numbers you hear',
            'visual_challenge'=>'Enter text in an image instead',
            'audio_challenge'=>'Enter numbers you hear instead',
            'refresh_btn'=>'Try another',
            'help_btn'=>'Help',
            'play_again'=>'Play the sound again',
            'cant_hear_this'=>'Download the sound as a MP3 file',
            'image_alt_text'=>'Image with text to enter'
        ) */
    
));
    if(
strlen($error))
        die(
'Error: '.$error);
    
$form->AddInput(array(
        
'TYPE'=>'submit',
        
'VALUE'=>'Submit',
        
'NAME'=>'doit'
    
));

    
/*
     * Always check if LoadInputValues returns any errors to detect any
     * configuration or reCAPTCHA access problem
     */
    
if(strlen($error $form->LoadInputValues($form->WasSubmitted('doit'))))
        die(
'Error processing reCAPTCHA response: '.$error);

    
$verify = array();
    if(
$form->WasSubmitted('doit'))
    {
        if((
$error_message $form->Validate($verify))=='')
            
$doit 1;
        else
        {
            
$doit 0;
            
$error_message HtmlSpecialChars($error_message);
        }
    }
    else
    {
        
$error_message '';
        
$doit 0;
    }

    if(!
$doit)
        
$form->ConnectFormToInput('captcha''ONLOAD''Focus', array());

    
$onload HtmlSpecialChars($form->PageLoad());

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test for Manuel Lemos' PHP form class using the reCAPTCHA plug-in input</title>
</head>
<body onload="<?php    echo $onload?>" bgcolor="#cccccc">
<center><h1>Test for Manuel Lemos' PHP form class using the reCAPTCHA plug-in input</h1></center>
<hr />
<?php
  
if($doit)
    {
?>
<center><h2>The entered text <?php echo $form->GetInputValue('captcha'); ?> is correct.</h2></center>
<?php
    
}
    else
    {
        
$form->StartLayoutCapture();
        
$title 'Form CAPTCHA plug-in test';
        
$body_template 'form_captcha_body.html.php';
        include(
'templates/form_frame.html.php');
        
$form->EndLayoutCapture();
        
$form->DisplayOutput();
    }
?>
<hr />
</body>
</html>