HTML_QuickForm2_Captcha
[ class tree: HTML_QuickForm2_Captcha ] [ index: HTML_QuickForm2_Captcha ] [ all elements ]

Source for file demo-captcha.php

Documentation is available at demo-captcha.php

  1. <?php session_start()?>
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  4.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6.     <head>
  7.         <title>HTML_QuickForm2_Element_Captcha demo</title>
  8.         <style type="text/css">
  9.             span.error {
  10.                 color: red;
  11.             }
  12.             div.row {
  13.                 clear: both;
  14.                 overflow: hidden;
  15.                 width: 100%
  16.             }
  17.             label {
  18.                 width: 200px;
  19.                 float: left;
  20.             }
  21.             div.element {
  22.                 float: left;
  23.             }
  24.             div.element.error input {
  25.                 background-color: #FAA;
  26.             }
  27.         </style>
  28.     </head>
  29.     <body>
  30.  
  31. <?php
  32.  
  33. // Ignore E_STRICT errors coming from some modules
  34. error_reporting(E_ALL ~E_STRICT ~E_DEPRECATED);
  35.  
  36. // You may not need to do this. For development purposes only
  37.     '../../' . PATH_SEPARATOR . get_include_path()
  38. );
  39.  
  40. require_once 'PEAR/Config.php';
  41. require_once 'HTML/QuickForm2.php';
  42. //require_once 'HTML/QuickForm2/Element/Captcha/Equation.php';
  43. require_once 'HTML/QuickForm2/Element/Captcha/Image.php';
  44. require_once 'HTML/QuickForm2/Element/Captcha/Numeral.php';
  45. require_once 'HTML/QuickForm2/Element/Captcha/ReCaptcha.php';
  46. //require_once 'HTML/QuickForm2/Element/Captcha/Word.php';
  47.  
  48. $form = new HTML_QuickForm2(
  49.     'captchaform1',
  50.     'post',
  51.     array(),
  52.     false // Change to true to use special ID in POST data
  53. );
  54.  
  55. $form->addElement(
  56.         'captcha[equation]',
  57.         array(
  58.             'id' => 'captcha_equation',
  59.         ),
  60.         array(
  61.             'label' => 'Equation',
  62.             'captchaType' => 'Equation',
  63.         )
  64.     )
  65. );
  66.  
  67. $form->addElement(
  68.         'captcha[figlet]',
  69.         array('id' => 'captcha_figlet'),
  70.         array(
  71.             'label' => 'Figlet',
  72.             'captchaType' => 'Figlet',
  73.             'font_file' => 'makisupa.flf'
  74.         )
  75.     )
  76. );
  77.  
  78. $form->addElement(
  79.         'captcha[image]',
  80.         array('id' => 'captcha_image'),
  81.         array(
  82.             'label' => 'Image',
  83.  
  84.             // Captcha options
  85.             'output' => 'png',
  86.             'width'  => 300,
  87.             'height' => 100,
  88.  
  89.             // Path where to store images
  90.             'imageDir' => __DIR__ . '/tmp/',
  91.             'imageDirUrl' => 'tmp/',
  92.  
  93.             'imageOptions' => array(
  94.                 'font_path'        => '/usr/share/fonts/truetype/ttf-dejavu/',
  95.                 'font_file'        => 'DejaVuSans.ttf',
  96.                 'text_color'       => '#000000',
  97.                 'background_color' => '#ffffff',
  98.                 'lines_color'      => '#000000',
  99.             )
  100.         )
  101.     )
  102. );
  103.  
  104. $form->addElement(
  105.         'captcha[numeral]',
  106.         array('id' => 'captcha_numeral'),
  107.         array(
  108.             'label' => 'Numeral',
  109.         )
  110.     )
  111. );
  112.  
  113. $form->addElement(
  114.         'captcha[recaptcha]',
  115.         array('id' => 'captcha_recaptcha'),
  116.         array(
  117.             'label' => 'ReCaptcha',
  118.             // Captcha options
  119.             // Please get your own keys. This here is for demo purposes only.
  120.             'public-key'  => '6LduXLoSAAAAAOH1LKWCyyqRsfE6SD6ZHOQg9kpr',
  121.             'private-key' => '6LduXLoSAAAAAH65fkp-xQHvekEBsNrt31SjBRZX'
  122.         )
  123.     )
  124. );
  125.  
  126. $form->addElement(
  127.         'captcha[word]',
  128.         array('id' => 'captcha_word'),
  129.         array(
  130.             'label' => 'Word',
  131.             'captchaType' => 'Word',
  132.             'locale' => 'en_US',//de
  133.         )
  134.     )
  135. );
  136.  
  137. $form->addElement(
  138.     'submit''submitted',
  139.     array('id' => 'submit''value' => 'Try it')
  140. );
  141.  
  142. if ($form->validate()) {
  143.     echo '<h3>valid</h3>';
  144.  
  145.     // Clear the session, otherwise the user can re-submit the form
  146.     // again and again
  147.     foreach ($form->getElements(as $element{
  148.         if ($element instanceof HTML_QuickForm2_Element_Captcha{
  149.             $element->clearCaptchaSession();
  150.         }
  151.     }
  152. else {
  153.     echo '<h3>Form</h3>';
  154.     echo $form;
  155. }
  156.  
  157. echo '<h2>Form data</h2>';
  158. echo '<pre>';
  159. var_export($form->getValue()true);
  160. echo '</pre>';
  161.  
  162. ?>
  163.  
  164.     </body>
  165. </html>

Documentation generated on Mon, 11 Mar 2019 15:55:05 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.