title: How to Keep Data fields When Recaptcha is Invalid
body: <p>My php contact form is working fine and I just need help on <strong>how to keep the data fields when recaptcha is incorrect or invalid.</strong> Where do I need to ad more script to accomplish this?
  Thank you very much for any answers. I am still new at php. This is ALL IN ONE PAGE Called: CONTACTFORM.php</p>
  
  <pre><code>&lt;?php
  
  
  require_once('recaptchalib.php');
  
  $publickey = "xxxxxxxxx";
  $privatekey = "xxxxxxxx";
  $error = false;
  $message = '';
  
  
  
  if (isset($_POST['send'])){     
      $resp = recaptcha_check_answer ($privatekey,
                                  $_SERVER["REMOTE_ADDR"],
                                  $_POST["recaptcha_challenge_field"],
                                  $_POST["recaptcha_response_field"]);
  
      if (!$resp-&gt;is_valid)
      {
          $error = true;      
          $message = 'Invalid Captcha Please try again';
      }
  
        if(!$error)
      {
          $emailTitle = 'Email from website!';
          $emailAddress = 'peace@hotmail.com';
  
          /* Gathering Data Variables */
  
          $emailField = $_POST['email'];
          $phoneField = $_POST['phone'];
          $nameField = $_POST['name'];
          $subjectField = $_POST['subject'];
          $messageField = $_POST['message'];
  
          $body = &lt;&lt;&lt;EOD
  &lt;br&gt;&lt;hr&gt;&lt;br&gt;
  Email: $emailField &lt;br /&gt;
  Phone: $phoneField &lt;br /&gt;
  Name: $nameField &lt;br /&gt;
  Subject: $subjectField &lt;br /&gt;
  Message: $messageField &lt;br /&gt;
  EOD;
          $headers = "From: $emailField\r\n";
          $headers .= "Content-type: text/html\r\n";
          $success = mail("$emailAddress", "$emailTitle", "$body", "$headers");
  
          $message = "Thank you! Your message has been sent.";
      }
  }
  ?&gt;
  
  &lt;form id="form1" name="form1" method="post" action="contactform.php"&gt;
        &lt;table width="100%" border="0" cellspacing="6" cellpadding="0"&gt;
          &lt;tr&gt;
            &lt;td align="right"&gt;&lt;label for="email" class="titulos"&gt;Email: &lt;/label&gt;&lt;/td&gt;
            &lt;td align="left"&gt;&lt;input name="email" type="text" id="email" size="35" maxlength="50" /&gt; 
              *&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td align="right"&gt;&lt;label for="phone" class="titulos"&gt;Phone: &lt;/label&gt;&lt;/td&gt;
            &lt;td align="left"&gt;&lt;input name="phone" type="text" id="phone" size="35" maxlength="50" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td align="right"&gt;&lt;label for="name" class="titulos"&gt;Name:&lt;/label&gt;&lt;/td&gt;
            &lt;td align="left"&gt;&lt;input name="name" type="text" id="name" size="35" maxlength="30" /&gt;
              *&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td align="right"&gt;&lt;label for="subject" class="titulos"&gt;Subject:&lt;/label&gt;&lt;/td&gt;
            &lt;td align="left"&gt;&lt;input name="subject" type="text" id="subject" size="35" maxlength="60" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td align="right" valign="top"&gt;&lt;label for="message" class="titulos"&gt;Message:&lt;/label&gt;&lt;/td&gt;
            &lt;td align="left"&gt;&lt;p&gt;
              &lt;textarea name="message" cols="27" rows="5" id="message"&gt;&lt;/textarea&gt;
              *&lt;/p&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td align="right"&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td align="left"&gt; 
            &lt;?php echo recaptcha_get_html($publickey);
      ?&gt;
  
  
  &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
  
            &lt;td align="right"&gt;&lt;label for="reset"&gt;&lt;/label&gt;&lt;/td&gt;
            &lt;td align="left"&gt;&lt;label for="send"&gt;&lt;/label&gt;
            &lt;input name="send" type="submit" id="send" onclick="MM_validateForm('email','','RisEmail','name','','R','message','','R');return document.MM_returnValue" value="Send Email" /&gt; &lt;label for="reset"&gt;&lt;/label&gt;
              &lt;input type="reset" name="reset" id="reset" value="Reset form" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td align="right"&gt;&amp;nbsp;&lt;/td&gt;
            &lt;td align="left" class="content"&gt;(*) Are Required fields&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td colspan="2" align="center"&gt;&lt;?php echo $message; ?&gt;
            &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/form&gt;
  </code></pre>