PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 26, 2022

[FIXED] how to add own CAPTCHA for my own contact form

 July 26, 2022     dreamweaver, forms, php     No comments   

Issue

I am creating a form using dreamweaver cc. the form is written in php and working good. now i want to add captcha image or text for verification method. how to possible using my code to add a captcha.

My form looking like this

<table width="100%" border="1" align="center" cellpadding="2">
<form method="post" action="contact_process.php"><tr>
<td><input type="text" name="name" placeholder="Enter Name" class="add_input_data" required/></td>
</tr>
 <tr>
 <td><input type="text" name="mobile" placeholder="Enter Mobile" class="add_input_data" required/></td>
</tr>
<tr>
 <td><select name="location" class="add_input_data">
 <option selected disabled>Location</option>
<option value="chittore">Chittore</option>
<option value="koduru">Koduru</option>
<option value="other">Other</option>
</select></td>
</tr>
<tr>
 <td><textarea name="address" class="add_input_textarea" placeholder="Enter Address" required></textarea></td>
</tr>
<tr>
 <td><input type="submit" name="submit" value="Submit" class="add_input_submit" align="right"/></td>
</tr></form>
</table>

my form processing script is looking like this

<?php 

$name = $_POST['name'];  
$mobile = $_POST['mobile'];  
$location = $_POST['location']; 
$address = $_POST['address']; 



$formcontent="From: $name \n Mobile : $mobile \n Location: $location \n      Address : $address";  
 $recipient = "dovariramu@gmail.com";  
  $subject = "New Connection Query";  


  mail($recipient, $subject, $formcontent) or die("Error!");  

 header('Location: thankyou.php');

 ?>

and my thankyou.php page with some content. here i am not showing.

Now I have two questions

1) when a user fill the data and click the submit button, the form display success full message from thankyou.php. but i want to display success full message with in a page(with simple scrolling success full message). 2) I want to add a captcha for this form. How to do this ?


Solution

for captcha you used, rand() method like:

<?php 
  $a = rand(1,9);
  $b = rand(1,9);
  $c = $a + $b; 
?>

In html, write

<h5> What is <?php echo $a; ?> + <?php echo $b; ?> ? </h5>
<input type="text" name="txt_value" id="txt_value" />

And now you can match both values ( $c with $("#txt_value").val() ) in jquery or on form submission, whatever make you easy.

Hope it helps...



Answered By - Shahzad Barkati
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing