Jump to content

how create a customer order form with captcha and validation in php?


sonita

Recommended Posts

hello ,i make a orderform for my website with out captcha and validation code.I would like to add captcha and validation code to the customer product order form.but i don`t know? how do i?this code is my form`s code :

<form id="sefareshform" action="result1.php" method="post"><table border="0px" width="450px"><tr align="right" valign="middle"><th width="100px"><label for="cufrist_name"> نام:</label><span class="required">*</span></th><td><input class="transparent" id="cufrist_name" maxlenght="50" name="cufrist_name" style="width:120px" type="text"/></td><th width="120px"><label for="culast_name">نام خانوادگی</label><span class="required">*</span></th><td><input class="transparent" id="culast_name" maxlenght="50" name="culast_name" style="width:120Px" type="text"/></td></tr><tr align="right" valign="middle"><th width="100px"><label for="phone"> تلفن ثابت</label><span class="required">*</span></th><td><input class="transparent" id="phone" maxlenght="20" name="phone" style="width:120px;" type="text"/></td><th width="100px"><label for="mobile"> موبایل</label><span class="required">*</span></th><td><input class="transparent" id="mobile" maxlenght="20" name="mobile" style="width:120px;" type="text"/></td></tr><tr align="right" valign="middle"><th width="100px"><label for="address"> آدرس</label><span class="required">*</span></th><td><input class="transparent" id="address" maxlenght="150" name="address" style="width:300px" type="text"/></td></tr><tr align="right" valign="middle"><th width="100px"><label for="email"> ایمیل</label><span class="required">*</span></th><td><input class="transparent" id="email" maxlenght="60" name="email" style="width:200px" type="text"/></td></tr><tr align="right" valign="middle"><th width="100px"><label for="product_name">نام محصول</label><span class="required">*</span></th><td><input class="transparent" id="product_name" maxlenght="25" name="product_name" style="width:120px" type="text"/></td><th width="100px"><label for="product_cod">کد محصول</label><span class="required">*</span></th><td><input class="transparent" id="product_cod" maxlenght="20" name="product_cod" style="width:120px" type="text"/></td></tr><tr align="right" valign="middle"><th width="100px"><label for="product_bod">ابعاد محصول</label><span class="required">*</span></th><td><input class="transparent" id="product_bod" maxlenght="20" name="product_bod" style="width:120px" type="text"/></td><th width="100px"><label for="tedadehaml">تعداد حمل</label><span class="required">*</span></th><td><input class="transparent" id="tedadehaml" maxlenght="10" name="tedadehaml" style="width:120px" type="text"/></td></tr><tr align="right" valign="middle"><th><label for="gheymatevahed">قیمت واحد</label><span class="required">*</span></th><td><input class="transparent" id="gheymatevahed" maxlenght="20" name="gheymatevahed" style="width:120px" type="text"></td><th><label for="etebargheymat">اعتبار قیمت</label><span class="required">*</span></th><td><input class="transparent" id="etebargheymat" maxlenght="20" name="etebargheymat" style="width:120px" type="text"></td></tr><tr align="right" valign="middle"><th width="100px"><label for="tarikh">تاریخ سفارش</label><span class="required">*</span></th><td><input class="transparent" id="tarikhsefaresh" maxlenght="10" name="tarikhsefaresh" style="width:120px" type="text"/></td><th width="100px"><label for="payment">نحوه پرداخت</label><span class="required">*</span></th><td><input class="transparent" id="payment" maxlenght="20" name="payment" style="width:120px" type="text"/></td></tr><tr align="right" valign="middle"><th><label for="mizanesefaresh">میزان سفارش</label><span class="required">*</span></th><td><input class="transparent" id="mizanesefaresh" maxlenght="20" name="mizanesefaresh" style="width:120px" type="text"></td><th><label for="color">رنگ محصول</label><span class="required">*</span></th><td><input class="transparent" id="color" maxlenght="20" name="color" style="width:120px" type="text"></td></tr><tr align="left" valign="middle"><td colspan="2"><input id="submit" style="width:100px;" type="submit" value="ثبت سفارش"/></td></tr></form>

> how add captcha and validation code with php to customer order form?how do i?please help me? very important.thanks.

Edited by sonita
Link to comment
Share on other sites

what have you tried? what are you stuck with? Have you looked online for any solutions, tutorials, anything?

Link to comment
Share on other sites

create an image, and do <?PHP$captcha = $_POST['captcha']; if($captcha == {what image says}){ die('Invalid Captcha'); } etc. I'm sure you know how to finish the rest

  • Like 1
Link to comment
Share on other sites

hello i write the customer order form with php and java script for validation and recaptcha, but my form showing many error. and don`t show recaptcha code? why? what`s meaning this error?this code is : my form code

<?phpsession_start();ob_start();error_reporting(-1);require_once 'config.php';require_once 'header.php';require_once 'db.php';?><!doctype html><html dir="rtl"><head><meta charset="utf8"/><title><?php echo TITR;?></title><link rel="stylesheet" type="text/css" href="style.css" /><!--<link rel="stylesheet" type="text/css" href="style1.css"/>--><script type="text/javascript">function validateForm(){var product_cod=document.forms["formsefaresh"]["product_cod"].value;var_err=document.getElementById("err");if(product_cod=null || product_cod==""){_err.innerHTML +="کدمحصول واردنشده یا اشتباه وارد شده است.لطفاکدمحصول راصحیح واردفرمایید.<br/>";}var cufrist_name=document.forms["formsefaresh"]["cufirst_name"].value;var_err=document.getElementById("err");if(cufrist_name=null || cufrist_name=="" || cufrist_name <'3'){_err.innerHTML +="نام شما کمترازسه حرف میباشد لطفا نام خودراصحیح وکامل واردنمایید.<br/>";}var culast_name=document.forms["formsefaresh"]["culast_name"].value;var_err=document.getElementById("err");if(culast_name=null || culast_name=="" || culast_name <'3'){_err.innerHTML +="نام خانوادگی شماکمترازسه حرف می باشد لطفا نام خانوادگی خود را صحیح واردنمایید.<br/>";}var phone=document.forms["formsefaresh"]["phone"].value;var_err=document.getElementById("err");if(phone=null || phone=="" || phone <10){_err.innerHTML +="تلفن واردشده کمتراز ده رقم میباشد،لطفا تلفن خود راصحیح واردنمایید.<br/>";}var mobile=document.forms["formsefaresh"]["mobile"].value;var_err=document.getElementById("err");if(mobile=null || mobile=="" || mobile<10){_err.innerHTML +="شماره همراه واردشده کمتراز ده رقم میباشد،لطفا شماره همراه خود را صحیح وارد نمایید.<br/>";}var mobile=document.forms["formsefaresh"]["mobile"].value;var_err=document.getElementById("err");if(mobile=null || mobile==""){_err.innerHTML +="<br/>";}var address=document.forms["formsefaresh"]["address"].value;var_err=document.getElementById("err");if(address=null || address=="" ){_err.innerHTML +="آدرس خود را وارد نکرده اید.لطفا آدرس  کامل خود را بطور صحیح واردنمایید.<br/>";}var address=document.forms["formsefaresh"]["email"].value;var_err=document.getElementById("err");if(email=null || email=="" ){_err.innerHTML +="آدرس ایمیل خود را واردنکرده اید یا معتبرنمیباشد،لطفا آدرس ایمیل معتبر واردنمایید.<br/>";}var product_name=document.forms["formsefaresh"]["product_name"].value;var_err=document.getElementById("err");if(product_name=null || product_name=="" ){_err.innerHTML +="نام محصول موردنظررا واردنکرده اید،لطفاآنراواردنمایید.<br/>";}var product_bod=document.forms["formsefaresh"]["product_bod"].value;var_err=document.getElementById("err");if(product_bod=null || product_bod=="" ){_err.innerHTML +="ابعاد موردنظر شما واردنشده است ،لطفا ابعادموردنیاز محصول موردنظرتان را واردنمایید.<br/>";}var gheymatevahed=document.forms["formsefaresh"]["gheymatevahed"].value;var_err=document.getElementById("err");if(gheymatevahed=null || gheymatevahed=="" ){_err.innerHTML +="قیمت واحد محصول موردنظر را واردنکرده اید،لطفا قیمت واحد را واردنمایید.<br/>";}var etebaregheymat=document.forms["formsefaresh"]["etebaregheymat"].value;var_err=document.getElementById("err");if(etebaregheymat=null || etebaregheymat=="" ){_err.innerHTML +="اعتبارقیمت محصول موردنظرخودراواردنکرده اید،لطفا آن را واردنمایید.<br/>";}var mizanesefaresh=document.forms["formsefaresh"]["mizanesefaresh"].value;var_err=document.getElementById("err");if(mizanesefaresh=null || mizanesefaresh=="" ){_err.innerHTML +="میزان سفارش خود را واردنکردهاید،لطفامیزان سفارش خود را واردنمایید.<br/>";}var tedadehaml=document.forms["formsefaresh"]["tedadehaml"].value;var_err=document.getElementById("err");if(tedadehaml=null || tedadehaml=="" ){_err.innerHTML +="تعداد حمل موردنظر خود را واردنکرده اید،لطفاآنرا مشخص و واردنمایید.<br/>";}var payment=document.forms["formsefaresh"]["payment"].value;var_err=document.getElementById("err");if(payment=null || payment=="" ) {_err.innerHTML +="نحوه پرداخت سفارش را واردنکرده اید،لطفا آنرا وارد نمایید.<br/>";}var tarikhsefaresh=document.forms["formsefaresh"]["tarikhsefaresh"].value;var_err=document.getElementById("err");if(tarikhsefaresh=null || tarikhsefaresh=="" ) {_err.innerHTML +="فیلد تاریخ سفارش خالی است،لطفاتاریخ سفارش خود را واردنمایید.<br/>";}var color=document.forms["formsefaresh"]["color"].value;var_err=document.getElementById("err");if(color=null || color=="" ) {_err.innerHTML +="رنگ محصول موردنظر خود را واردنکرده اید،لطفا رنگ  موردنظر برای سفارش خود را واردنمایید.<br/>";}return false;}</script></head><body>     فرم سفارش<div class="sidebar3">   <div class="m"><a href="index.php">صفحه اصلی</a></div>		    <div class="m"><a href="ajori.php">طرح آجري</a></div>   <div class="m"><a href="pazel.php">طرح پازل</a></div>   <div class="m"><a href="hasir.php">طرح حصیری</a></div>   <div class="m"><a href="gheychi.php">طرح قیچی</a></div>   <div class="m"><a href="namonazam.php">طرح نامنظم</a></div>   <div class="m"><a href="kharej.php">نمای خارجی</a></div>   <div class="m"><a href="dakhel.php">نمای داخلی</a></div>   <div class="m"><a href="kaf.php">نمای کف</a></div>   <div class="m"><a href="factory.php">درباره کارخانه</a></div>   <div class="m"><a href="manager.php">درباره مسولان</a></div>   <div class="m"><a href="kharid.php">راهنمای خرید</a></div>   <div class="m"><a href="pardakht.php">راهنمای پرداخت</a></div>   <div class="m"><a href="contact.php">ارتباط با ما</a></div>   <div class="m"><a href="support.php">پشتیبانی</a></div>   <div class="m"><a href="form.php">فرم سفارش</a></div>   <div class="m"><a href="peygiri.php">پیگیری سفارش</a></div>  </div> <div id="contactform" dir="rtl">	  <div  dir="rtl">  <?php  $con=mysql_connect("localhost","root","");  mysql_select_db("keivandb",$con);   $cufrist_name=$_POST['cufrist_name'];  $culast_name=$_POST['culast_name'];  $phone=$_POST['phone'];  $mobile=$_POST['mobile'];  $address=$_POST['address'];  $email=$_POST['email'];  $product_cod=$_POST['product_cod'];  $product_name=$_POST['product_name'];  $product_bod=$_POST['product_bod'];  $gheymatevahed=$_POST['gheymatevahed'];  $etebaregheymate=$_POST['etebaregheymat'];  $mizanesefaresh=$_POST['mizanesefaresh'];  $tedadehaml=$_POST['tedadehaml'];  $payment=$_POST['payment'];  $tarikhsefaresh=$_POST['tarikhsefaresh'];  $color=$_POST['color'];     //cufrist_name  if($cufrist_name=null || $cufrist_name=="" ||$cufrist_name <3) {  echo "نام وارد شده کمتر از سه حرف میباشد،لطفا نام خود را صحیح واردنمایید.<br/>";  }  //culast_name   if($culast_name=null || $culast_name=="" ||$cufrist_name <3) {  echo "نام خانوادگی شما کمتر از سه حرف می باشد یا وارد نشده ،لطفا نام خانوادگی خود را واردنمایید.<br/>";  }  //phone  if($phone=null || $phone=="" || $phone<10) {  echo "تلفن وارد شده کمترازده رقم می باشد،لطفا شماره تلفن را صحیح وارد نمایید.<br/>";  }  //mobile  if($mobile=null || $mobile=="" ||$mobile<10){  echo "تلفن همراه واردشده کمترازده رقم می باشد،لطفا شماره همراه خود را بطور صحیح واردنمایید.<br/>";  }  //address  if($address=null || $address=="") {  echo "شما آدرس خود را وارد ننموده اید،لطفا آدرس دقیق خود را بطورکامل وارد نمایید.<br/>";  }  //email  if($email=null || $email==""){  echo "شما ایمیل خود ا وارد ننموده اید،لطفا ایمیل خود را وارد نمایید.<br/>";  }  //product_cod  if($product_cod=null || $product_cod==""){  echo "شما کد محصول مورد نظر خود را وارد ننموده اید،لطفاآن را وارد نماید.<br/>";  }  //product_name  if($product_name=null || $product_name==""){  echo "شما نام محصول مورد نظر خود را وارد نکرده اید،لطفا آن راواردنمایید.<br/>";  }  //product_bod  if($product_bod=null || $product_bod==""){  echo "ابعاد محصول مورد نظرشما چیست؟آن را واردنکرده اید،لطفاآن را واردنمایید.<br/>";  }  //gheymatevahed  if($gheymatevahed==null || $gheymatevahed==""){  echo "قیمت واحد درج شده زیر محصول موردنظر را واردننموده اید،لطفاقیمت واحد راواردنمایید.<br/>";  }  //etebaregheymat  if($etebaregheymat=null || $etebaregheymat=="") {  echo "لطفا تاریخ اعتبار قیمت محصول مورد نظر خود را واردنمایید.<br/>";  }  //mizanesefaresh  if($mizanesefaresh=null || $mizanesefaresh==""){  echo "میزان سفارش محصول موردنظرشما چقدراست؟لطفا آن را به متر واردنمایید.<br/>";  }  //tedadehaml  if($tedadehaml=null || $tedadehaml==""){  echo "شما فیلد تعداد حمل را وارد ننموده اید،لطفا آن را وارد نمایید.<br/>";  }  //payment  if($payment=null || $payment==""){  echo "لطفا نحوه پرداخت را واردنماید،شما آن را وارد ننموده اید.<br/>";  }  //tarikhsefaresh  if($tarikhsefaresh=null || $tarikhsefaresh==""){  echo "لطفا تاریخ سفارش را وارد نمایید،شما این فیلد را پر ننموده اید.<br/>";  }  //color  if($color=null || $color==""){  echo "رنگ مورد نظر برای سفارش شما چیست؟لطفا ان راوارد نمایید.<br/>";  }  // recaptcha code  if($recaptch=="" || $recaptcha=null || $recaptcha !=$_SESSION['recaptcha']){  echo "کد وارد شده صحیح نمی باشد،لطفا کد صحیح را وارد نمایید.<br/>";  } else {// $sql="INSERT INTO orders(cufrist_name,culast_name,phone,mobile,address,email,product_cod,product_nmae,product_bod,gheymatevahed,etebaregheymat,// mizanesefaresh,payment,tarikhsefaresh,color) VALUES ('".$cufrist_name."','".$culast_nmae."','".$phone."','".$mobile."','".$address."', '".$email."','".$product_cod."',// '".$product_name."','".$product_bod."','".$gheymatevahed."','".etebaregheymate."','".$mizanesefaresh."',//,'".$tedadehaml."','".$payment."','".$tarikhsefaresh."','".$color."')";  }   echo "   <?php  require_once('recaptchalib.php');  $publickey='6Lel4lSAAAAAluYh2isoRgQL9jLt3ylqlN6Vg8';  echo recaptcha_get_html($publickey);  ?>   <form id='formsefaresh'  name='formsefaresh' action='verify.php'  on submit='return validateForm()' method='post'>  <p><strong>نام: </strong><span class='required'>*</span>  <input id='cufrist_name' type='text' name='cufrist_name' value='".$cufrist_name."' /></p>  <p><strong>نام خانوادگی: </strong><span class='required'>*</span>  <input id='culast_name' type='text' name='culast_name' value='".$culast_name."' /></p>  <p><strong> تلفن ثابت:</strong><span class='required'>*</span>  <input id='phone' type='text' name='phone' value='".$phone."' /></p>  <p><strong> تلفن همراه:</strong><span class='required'>*</span>  <input id='mobile' type='text' name='mobile' value='".$mobile." '/></p>  <p><strong>آدرس:</strong><span class='required'>*</span>  <input id='address' type='text' name='address' value='".$address." '/></p>  <p><strong> پست الکترونیک:</strong><span class='required'>*</span>  <input id='email' type='text' name='email' value='".$email." '/></p>  <p><strong>کدمحصول: </strong><span class='required'>*</span>  <input id='product_cod' type='text' name='product_cod' value='".$product_cod."' /></p>  <p><strong>نام محصول: </strong><span class='required'>*</span>  <input id='product_name' type='text' name='product_name' value='".$product_name."' /></p>  <p><strong>ابعادمحصول: </strong><span class='required'>*</span>  <input id='product_bod' type='text' name='product_bod' value='".$product_bod."' /></p>  <p><strong>قیمت واحد:</strong><span class='required'>*</span>  <input id='gheymatevahed' type='text' name='gheymatevahed' value='".$gheymatevahed."' /></p>  <p><strong>اعتبارقیمت:</strong><span class='required'>*</span>  <input id='etebaregheymat' type='text' name='etebaregheymat' value='".$etebaregheymat."' /></p>  <p><strong>میزان سفارش:</strong><span class='required'>*</span>  <input id='mizanesefaresh' type='text' name='mizanesefaresh' value='".$mizanesefaresh."' /></p>  <p><strong>تعدادحمل:</strong><span class='required'>*</span>  <input id='tedadehaml' type='text' name='tedadehaml' value='".$tedadehaml." '/></p>  <p><strong>نحوه پرداخت:</strong><span class='required'>*</span>  <input id='payment' type='text' name='payment' value='".$payment."' /></p>   <p><strong>تاریخ سفارش:</strong><span class='required'>*</span>  <input id='tarikhsefaresh' type='text' name='tarikhsefaresh' value='".$tarikhsefaresh."' /></p>  <p><strong>رنگ محصول:</strong><span class='required'>*</span>  <input id='color' type='text' name='color' value='".$color."' /></p>  <p><strong>تصویر امنیتی زیر را وارد کنید:</strong><span class='required'>*</span>  <input id='recaptcha' type='text' name='recaptcha' value='' />  <button>ثبت سفارش:</button></p>   </form>" ;?>    </div><!-- rtl -->   </div><!-- contentpage rtl -->  </body></html><?phpob_end_flush();?>

this code is verify.php:

<?php   require_once('recaptchalib.php');   $privatekey="6Lel4lAAAAAl28lolQKCZBh8jqCG8NKcUBEMgH";   $resp=recaptcha_check_answer($privatekey,   $_SERVER["REMOTE_ADDER"],   $_POST["recaptcha_challenge_field"],   $_post["recaptcha_response_field"]);   if(!$resp->is_valid){   //درصورتیکه مقدار وارد شده صحیح نباشداین قسمت اجرامی شود.   die("تصویر امنیتی واردشده صحیح نمیباشد،لطفا کد راصحیح وارد نمایید."."(recaptcha said:".$resp->error.")");   } else{   //درصورتی که مقدار واردشده صحیح باشد این قسمت اجرا می شود.   echo "کدی که شما وارد کرده اید معتبر می باشد.";   }   ?>

please help me.

Link to comment
Share on other sites

my question above and showing there error following:(that errors above say): how do i resolve this errors and problem?please help me.

1-( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: cufrist_name in C:\wamp\www\Test3\form.php on line 140

2-) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: culast_name in C:\wamp\www\Test3\form.php on line 141

3-( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: phone in C:\wamp\www\Test3\form.php on line 142

4-( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: mobile in C:\wamp\www\Test3\form.php on line 143

5-( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: address in C:\wamp\www\Test3\form.php on line 144

6-( ! ) SCREAM: Error suppression ignored for

( ! ) Notice: Undefined index: email in C:\wamp\www\Test3\form.php on line 145

7-) Notice: Undefined index: product_cod in C:\wamp\www\Test3\form.php on line 146

8- Notice: Undefined index: product_name in C:\wamp\www\Test3\form.php on line 147

9- Notice: Undefined index: product_bod in C:\wamp\www\Test3\form.php on line 148

10-Notice: Undefined index: gheymatevahed in C:\wamp\www\Test3\form.php on line 149

11- Notice: Undefined index: etebaregheymat in C:\wamp\www\Test3\form.php on line 150

12-) Notice: Undefined index: mizanesefaresh in C:\wamp\www\Test3\form.php on line 151

13-) Notice: Undefined index: tedadehaml in C:\wamp\www\Test3\form.php on line 152

14-Notice: Undefined index: payment in C:\wamp\www\Test3\form.php on line 153

15-Notice: Undefined index: tarikhsefaresh in C:\wamp\www\Test3\form.php on line 154

16-Notice: Undefined index: color in C:\wamp\www\Test3\form.php on line 155

17-Notice: Undefined variable: etebaregheymat in C:\wamp\www\Test3\form.php on line 198

18- Notice: Undefined variable: recaptch in C:\wamp\www\Test3\form.php on line 222

please help me. very very important.thanks

Link to comment
Share on other sites

well, the good part is that you have all the errors there. have you tried investigating them, since you are given the line number and the specific issue the look for? I would start going through them one by one. they are all very common and errors to handle. They primarily all seem to be undefined index errors, which simply means you are trying to access an array element that doesn't exist. Double check your arrays are what you think they are, and have what you contain. double check the indexes you are using and make sure they match. The biggest issue I see you doing is using $_POST members without checking if they exist first. when it comes to form handling on the same page as the form, you should typically be checking to see if the form was submitted, before trying to access the $_POST members that would eventually become populated when the form actually gets submitted.

Link to comment
Share on other sites

Other than the normal form errors from not checking if the form was submitted, you also have a couple mispellings. The 2 errors about undefined variables are because you misspelled the variable names. Other than that, you aren't using recaptcha correctly. For this part:

echo "<?phprequire_once('recaptchalib.php');$publickey='6Lel4lSAAAAAluYh2isoRgQL9jLt3ylqlN6Vg8';echo recaptcha_get_html($publickey); ?>

You aren't supposed to echo PHP code, you don't want to print the PHP code, you want to run it. That should not be inside an echo statement, it's just PHP code. The echo statement to output the recaptcha HTML needs to go inside your form, not outside of it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...