如何为我自己的联系表添加自己的验证码 [英] how to add own CAPTCHA for my own contact form

查看:75
本文介绍了如何为我自己的联系表添加自己的验证码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Dreamweaver CC创建表单。该表格是用php编写的,运行良好。现在我想添加验证码图像或文本作为验证方法。

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.

我的表单看起来像这样

<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');

 ?>

和我的thankyou.php页面,其中包含一些内容。

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

现在我有两个问题

1)当用户填写数据并单击提交按钮,表单将显示来自thankyou.php的成功完整消息。但是我想在页面中显示成功的完整消息(简单滚动成功的完整消息)。
2)我想为此表格添加一个验证码。

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 ?

推荐答案

用于您使用的验证码, rand()方法,如:

for captcha you used, rand() method like:

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

在html中,写

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

现在您可以将两个值($ c与$(# txt_value)。val())可以在jquery中或在表单提交时使用,只要让您轻松即可。

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

希望它会有所帮助。 。

这篇关于如何为我自己的联系表添加自己的验证码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆