PHP Classes

Can't Display Captcha Image

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  All threads  >  Can't Display Captcha Image  >  (Un) Subscribe thread alerts  
Subject:Can't Display Captcha Image
Summary:Failure of Captcha image to display at all
Messages:3
Author:Albert Padley
Date:2006-08-05 17:53:28
Update:2006-08-05 19:32:55
 

  1. Can't Display Captcha Image   Reply   Report abuse  
Picture of Albert Padley Albert Padley - 2006-08-05 17:53:28
I have an existing form that I am trying to add a Captcha input to. The Captcha image does not display.

When accessing the test_captcha_form.php page, the Captcha image does display. So, the problem is not with GD or mcrypt.

I copied the following code from the test_captcha_form.php page and pasted it into my existing form page.

At the top of the page:

require("form_captcha.php");

$key="my secret key"; // Tried various keys

In the define fields section:

$error=$form->AddInput(array(
"TYPE"=>"custom",
"ID"=>"captcha",
"LABEL"=>"<u>E</u>nter the following text:",
"ACCESSKEY"=>"E",
"CustomClass"=>"form_captcha_class",
"Key"=>$key,
/* "Format"=>"{image} {text} {redraw}{validation}", */
/* "ImageWidth"=>80, */
/* "ImageHeight"=>20, */
/* "TextLength"=>4, */
/* "TextColor"=>"#000000", */
"ImageFormat"=>"png",
"NoiseFromPNGImage"=>"noise.png",
/*
* If you have installed GD with GIF support, you may uncomment these
* lines.
*/
/* "ImageFormat"=>"gif", */
/* "NoiseFromGIFImage"=>"noise.gif", */
"ResetIncorrectText"=>1,
"BackgroundColor"=>"#FFFFFF",
"ValidationErrorMessage"=>"The validation text is not correct. Please enter it again.",
"ExpiryTime"=>60,
"ExpiryTimeValidationErrorMessage"=>"The validation text has expired."
));
if(strlen($error))
die("Error: ".$error);

At the end of the define fields section:

/*
* This code is necessary to handle the requests for serving the captcha
* image.
* Do not remove it nor output any data or headers before these lines.
*/
$form->HandleEvent($processed);
if($processed)
exit;

Did I miss something?

The form can be seen at www.billgarrettconstruction.com/formsgen/projectform.php

Thanks.

  2. Re: Can't Display Captcha Image   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-08-05 18:54:53 - In reply to message 1 from Albert Padley
If you open the URL of the image, you can see that you are outputting the page header before image output. This means that your script outputs the page header before calling the HandleEvent function.

  3. Re: Can't Display Captcha Image   Reply   Report abuse  
Picture of Albert Padley Albert Padley - 2006-08-05 19:32:55 - In reply to message 2 from Manuel Lemos
Yes, you are right. Fixing that made it work.

Thanks.