Location: PHPKode > projects > BotDetect CAPTCHA > BotDetect-PHP-CAPTCHA-Component-vAlpha1-Build201202051720/WebApp/PhpFormCaptchaSample/index.php
<?php session_start(); ?>
<!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>
  <title>BotDetect PHP CAPTCHA Form Sample</title>
  <link type="text/css" rel="Stylesheet" href="StyleSheet.css" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <?php require("BotDetect.php"); ?>
</head>
<body>
  <form method="post" action="ProcessForm.php" id="form1">

    <h1>BotDetect PHP CAPTCHA Form Sample</h1>
    
    <fieldset>
      <legend>CAPTCHA included in PHP form validation</legend>
      
      <div class="input">
				<label for="Name">Name:</label>
				<input type="text" name="Name" id="Name" class="textbox" value="<?php if (isset($_REQUEST["Name"])) { echo $_REQUEST["Name"]; } ?>" />
				<?php // name validation failed, show error message      
				if (isset($_REQUEST["nameValid"]) && $_REQUEST["nameValid"] == false) { ?>
					<span class="incorrect">*</span><?php 
				}
			  ?>
			</div>
			
			<div class="input">
				<label for="Email">Email:</label>
				<input type="text" name="Email" id="Email" class="textbox" value="<?php if (isset($_REQUEST["Email"])) { echo $_REQUEST["Email"]; } ?>" />
				<?php // email validation failed, show error message
				if (isset($_REQUEST["emailValid"]) && $_REQUEST["emailValid"] == false) { ?>
					<span class="incorrect">*</span><?php 
				}
			  ?>
			</div>
			
			<div class="input">
				<label for="Message">Short message:</label>
				<textarea class="inputbox" id="Message" name="Message" rows="5" cols="40"><?php if (isset($_REQUEST["Message"])) { echo $_REQUEST["Message"]; } ?></textarea>
				<?php // message validation failed, show error message
				if (isset($_REQUEST["messageValid"]) && $_REQUEST["messageValid"] == false) { ?>
					<span class="incorrect">*</span><?php 
				}
			  ?>
			</div>
      
      
      <div class="input">
        <?php // Adding BotDetect Captcha to the page 
				  $FormCaptcha = new Captcha("FormCaptcha");
          $FormCaptcha->UserInputID = "CaptchaCode";
					
          // only show the Captcha if it hasn't been already solved for the current message
					if(!$FormCaptcha->IsSolved) { ?>
					  <label for="CaptchaCode">Retype the characters from the picture:</label>
					  <?php echo $FormCaptcha->Html(); ?>
					  <input type="text" name="CaptchaCode" id="CaptchaCode" class="textbox" /><?php
						// Captcha validation failed, show error message
						if (isset($_REQUEST["captchaValid"]) && $_REQUEST["captchaValid"] == false) { ?>
							<span class="incorrect">*</span><?php
						} 
					}
			  ?>
			</div>
      
			<input type="submit" name="SubmitButton" id="SubmitButton" value="Submit"  />
      
    </fieldset>
    
    <div id="notes">
			<div class="note">
				<h3>Description</h3>
				<p>This sample project shows how to add BotDetect CAPTCHA protection to a typical PHP form.</p> 
				<p>Captcha validation is integrated with other form fields validation, and only submissions that meet all validation criteria are accepted.</p> 
				<p>If the Captcha is sucessfully solved but other field validation fails, the Captcha is hidden since the users have already proven they are human.</p>
				<p>This kind of validation could be used on various types of public forms which accept messages, and are at risk of unwanted automated submissions.</p> 
				<p>For example, it could be used to ensure bots can't submit anything to a contact form, add guestbook entries, blog post comments or anonymous message board / forum replies.</p> 
			</div>
			<div class="note warning">
				<h3>Please Note</h3>
				<p>BotDetect PHP Captcha Library Alpha is a work in progress, and we need you to guide our efforts towards a polished product. Please <a href="http://captcha.biz/contact.html?topic=php">let us know</a> if you encounter any bugs, implementation issues, or a usage scenario you would like to discuss.</p>
    <p>The PHP library does not yet support the full feature set of the other BotDetect 3.0 Captcha products (ASP.NET and ASP Classic). Captcha localization and Captcha sounds are not implemented yet, but are coming soon.</p>
			</div>
    </div>
  </form>
</body>
</html>
Return current item: BotDetect CAPTCHA