PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Axel Pardemann   AMDev_Captcha   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Form with embeded CAPTCHA
Class: AMDev_Captcha
Generate form elements for CAPTCHA validation
Author: By
Last change: Removed repeated <html> tag
Date: 15 years ago
Size: 2,102 bytes
 

Contents

Class file image Download
<?php require_once("AMDev.Tools.Captcha.php"); ?>
<?php
$init
= array(
   
"CAPTCHA_CLASS" => "amdev_captcha",
   
"LANGUAGE_FILE" => "captcha/languages/es.lng",
   
"REFRESH_ENABLED" => true
);
$captcha = new AMDev_Captcha($init);

// Sanitize inputs
$captcha->SanitizeFormData();

// Start buffering. Needed if using $captcha->RedirectPost() (Don't for get to EndBuffering() at the end of the page)
$captcha->StartBuffering();

// Validate captcha from the beginning to have the results right away
$captchaValidation = $captcha->ValidateCaptcha();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Captcha</title>
<?php echo $captcha->GetXajaxScript(); ?>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
if($captchaValidation != 0 || $captchaValidation != 1){
   
$errMsg = "An error ocurred: ";
    if(
$captchaValidation == 2)
       
$errMsg .= $captcha->DisplayErrorMsg("ERR_INVALID_CHARS");
    elseif(
$captchaValidation == 3)
       
$errMsg .= $captcha->DisplayErrorMsg("ERR_MAX_TRIES_REACHED");

   
$errMsg .= "<br /><br />";
}
?>
<form id="captcha_test" name="captcha_test" method="post" action="<?php print($_SERVER["SCRIPT_NAME"]); ?>">
  Name:&nbsp;
  <input type="text" name="txtName" id="txtName" /><br />
Surname:&nbsp;<input type="text" name="txtSurname" id="txtSurname" /><br />
<?php
switch($captchaValidation)
{
    case
0:
        print(
$captcha->DisplayFormPart());
        break;
    case
1:
       
// Congratulation. You will get the resource now
       
$captcha->RedirectPost("redirect.php");
        break;
    case
2:
        echo
"<br />".$captcha->DisplayErrorMsg("ERR_INVALID_CHARS");
        echo
$captcha->DisplayFormPart();
        break;
    case
3:
        echo
"<br />".$captcha->DisplayErrorMsg("ERR_MAX_TRIES_REACHED");
        break;
}
?>
<br />
<input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
</form>
</body>
</html>
<?php $captcha->EndBuffering(); ?>