douna3367 2014-02-16 06:18
浏览 58
已采纳

联系表格验证码显示未定义的索引通知

I'm trying to implement captcha validation for a contact form. I'm getting the following error for every textbox:

`>Notice Undefined index: name in contact1.php on line 16

Notice Undefined index: name in contact1.php on line 21
Notice Undefined index: name in contact1.php on line 26
Notice Undefined index: name in contact1.php on line 41`

contact.php:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 <title>PHP Contact Form with Captcha</title>
 </head>

 <body>
 <form action="mailer.php" method="post" name="form1" id="form1" style="margin:0px;  font-  family:Verdana, Arial, Helvetica, sans-serif;font-size:11px; width:300px;"   onsubmit="MM_validateForm('from','','RisEmail','subject','','R','verif_box','','R','message'      ,'','R');return document.MM_returnValue">

  Your Name:<br />
 <input name="name" type="text" id="name" style="padding:2px; border:1px solid #CCCCCC;    width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;"   value="<?php echo $_GET['name'];?>"/>
 <br />
 <br />

 Your e-mail:<br />
 <input name="from" type="text" id="from" style="padding:2px; border:1px solid #CCCCCC;  width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;"  value="<?php echo $_GET['from'];?>"/>
 <br />
 <br />

 Subject:<br />
 <input name="subject" type="text" id="subject" style="padding:2px; border:1px solid  #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font- size:11px;" value="<?php echo $_GET['subject'];?>"/>
 <br />
 <br />

 Type verification image:<br />
 <input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid   #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-  size:11px;"/>
  <img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image,   type it in the box" width="50" height="24" align="absbottom" /><br />
   <br />

  <!-- if the variable "wrong_code" is sent from previous page then display the error  field -->
  <?php if(isset($_GET['wrong_code'])){?>
  <div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF;   padding:4px; padding-left:6px;width:295px;">Wrong verification code</div><br /> 
  <?php ;}?>

  Message:<br />
    <textarea name="message" cols="6" rows="5" id="message" style="padding:2px; border:1px solid #CCCCCC; width:300px; height:100px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"><?php echo $_GET['message'];?></textarea>
    <noscript><a href="http://www.thewebhelp.com" style="display:none;">contact form by   thewebhelp</a></noscript>
    <input name="Submit" type="submit" style="margin-top:10px; display:block; border:1px     solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif;   font-size:11px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px;   line-height:14px; background-color:#EFEFEF;" value="Send Message"/>
    </form>
    </body>
    </html>

verificationimage.php

  <?php


   header('Content-type: image/jpeg');

  $width = 50;
  $height = 24;

   $my_image = imagecreatetruecolor($width, $height);

   imagefill($my_image, 0, 0, 0xFFFFFF);

   // add noise
  for ($c = 0; $c < 40; $c++){
      $x = rand(0,$width-1);
      $y = rand(0,$height-1);
      imagesetpixel($my_image, $x, $y, 0x000000);
     }

  $x = rand(1,10);
  $y = rand(1,10);

   $rand_string = rand(1000,9999);
   imagestring($my_image, 5, $x, $y, $rand_string, 0x000000);

  setcookie('tntcon',(md5($rand_string).'a4xn'));

  imagejpeg($my_image);
  imagedestroy($my_image);
 ?>



  mailer.php
  enter code here
  <?php
 $name = $_REQUEST["name"];
 $subject = $_REQUEST["subject"];
 $message = $_REQUEST["message"];
 $from = $_REQUEST["from"];
 $verif_box = $_REQUEST["verif_box"];

 $name = stripslashes($name); 
 $message = stripslashes($message); 
 $subject = stripslashes($subject); 
 $from = stripslashes($from); 

 if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
  $message = "Name: ".$name."
".$message;
  $message = "From: ".$from."
".$message;
  mail("adriantadeo14@rocketmail.com", 'Online Form: '.$subject,     $_SERVER['REMOTE_ADDR']."

".$message, "From: $from");
  setcookie('tntcon','');
   } else {

   header("Location:".$_SERVER['HTTP_REFERER']."?  subject=$subject&from=$from&message=$message&wrong_code=true");
   exit;
  }
  ?>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
         <title>PHP Contact Form Redirect</title>
      </head>

        <body>
       </body>
       </html>

How can I fix this issue?

  • 写回答

2条回答 默认 最新

  • dousi9215 2014-02-16 06:32
    关注

    From your comment , you have mentioned that you are calling the contact.php URL as http://localhost/date2/captcha/php-contact-form/contact.php

    But as you can see from your code.. The contact.php expects $_GET parameters.

    <input name="name" type="text" id="name" style="padding:2px; border:1px solid #CCCCCC;    width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;"   value="<?php echo $_GET['name'];?>"/>
    

    So you need to pass those parameters along with the URL. See your line 16 as where the notice was thrown.

    The code ..

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>PHP Contact Form with Captcha</title>
    </head>
    
    <body>
    <form action="mailer.php" method="post" name="form1" id="form1" style="margin:0px;  font-  family:Verdana, Arial, Helvetica, sans-serif;font-size:11px; width:300px;"   onsubmit="MM_validateForm('from','','RisEmail','subject','','R','verif_box','','R','message'      ,'','R');return document.MM_returnValue">
    
        Your Name:<br />
        <input name="name" type="text" id="name" style="padding:2px; border:1px solid #CCCCCC;    width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;"   value=""/>
        <br />
        <br />
    
        Your e-mail:<br />
        <input name="from" type="text" id="from" style="padding:2px; border:1px solid #CCCCCC;  width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;"  value=""/>
        <br />
        <br />
    
        Subject:<br />
        <input name="subject" type="text" id="subject" style="padding:2px; border:1px solid  #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font- size:11px;" value=""/>
        <br />
        <br />
    
        Type verification image:<br />
        <input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid   #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-  size:11px;"/>
        <img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image,   type it in the box" width="50" height="24" align="absbottom" /><br />
        <br />
    
        <!-- if the variable "wrong_code" is sent from previous page then display the error  field -->
        <?php if(isset($_GET['wrong_code'])){?>
            <div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF;   padding:4px; padding-left:6px;width:295px;">Wrong verification code</div><br />
            <?php ;}?>
    
        Message:<br />
        <textarea name="message" cols="6" rows="5" id="message" style="padding:2px; border:1px solid #CCCCCC; width:300px; height:100px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"></textarea>
        <noscript><a href="http://www.thewebhelp.com" style="display:none;">contact form by   thewebhelp</a></noscript>
        <input name="Submit" type="submit" style="margin-top:10px; display:block; border:1px     solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif;   font-size:11px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px;   line-height:14px; background-color:#EFEFEF;" value="Send Message"/>
    </form>
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入