Simple contact form HTML with Captcha?
Solution 1
If you have been struggling to implement recaptcha just go for
$a=rand(2,9); // this will get a number between 2 and 9
$b=rand(2,9); // this will also get a number between 2 and 9. You can change this according to your wish
$c=$a+$b;
On the php page just show
echo $a."+".$b."="<input type="text" name="recaptcha" />
and check whether the textbox value is equal to $c.
This is the most simple recaptcha sort of thing you can implement to prevent bots.
Solution 2
Step 1
-
You need some code to generate a graphical font image representation web captcha. you must have GD library for generating font image.
<?php session_start(); $RandomStr = md5(microtime()); $ResultStr = substr($RandomStr,0,5); $NewImage =imagecreatefromjpeg("bgimage.jpg"); $LineColor = imagecolorallocate($NewImage,233,239,239); $TextColor = imagecolorallocate($NewImage, 255, 255, 255); imageline($NewImage,1,1,40,40,$LineColor); imageline($NewImage,1,100,60,0,$LineColor); $font = imageloadfont("font.gdf"); imagestring ($NewImage, $font, 5, 5, $ResultStr, $TextColor ); $_SESSION['originalkey'] = $ResultStr; //store the original coderesult in session variable header("Content-type: image/jpeg"); imagejpeg($NewImage); ?>
Step 2
-
Now your form to call captcha.
<form action="submit.php" method="post" name="form1"> Name: <input type="text" name="name" value="" /> <br /> Email Address: <input type="text" name="email" value="" /> <br /> Message: <textarea name="message" cols="30" rows="6"></textarea> <br /> <img src="php_captcha.php" /> <input name="captcha" type="text" id="captcha" size="15" /> <br /> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="clear"/> </form>
Step 3
-
Now this is last step to form submiting time check capcha validation. Using session information.
<?php $originalkey = substr($_SESSION['originalkey'],0,5); //session of captcha $captcha = $_REQUEST['captchacode']; if($captcha!=$originalkey){ print_error("<b> Captcha does not match, Go back and try again.</b>"); } ?>
Hope this help you!
Solution 3
Visit here this might solve your problem.Its simple form with explanation.
http://www.html-form-guide.com/contact-form/html-contact-form-captcha.html
5AMWE5T
Updated on June 30, 2020Comments
-
5AMWE5T almost 4 years
I am looking for a simple HTML for a contact form that has ReCaptcha or some type of anti-spam features. I tried multiple tutorials but they are all complicated and I can't get any to work. All I need is an Name, Email, and Message field (and also the ReCaptcha and submit button). Does anyone know where I can find a simple contact form HTML?
-
Jaykumar Patel over 10 yearsGD library is php graphics library. this library already include in newer version PHP. but older php version not add manually. this library is use for generate capcha number and store in variable to compare user entered captcha and real captcha both are same ?
-
Jaykumar Patel over 10 yearsIf you are use WAMP server you havve to show "Loaded Extensions" in WAMP localhost homepage.
-
5AMWE5T over 10 yearsI tried this tutorial but when I put the html in the site there is code inside all the forms already so that doesn't really work.
-
Indra about 10 yearsno GD library.. how to install?
-
Jaykumar Patel about 10 yearsHow to instal GD library Read This. but i suggest you install latest PHP version or WAMP it's include GD library.