重新显示填写了字段的表单

时间:2011-10-25 10:54:14

标签: forms contact verification

我需要一些帮助来重新显示表单。

基本上,目前用户将填写我的联系表格,表格及其内容将传递到我的验证页面,如果正确输入了重新表格,则会转到感谢页面。

当重新输入recaptcha时,我想重新显示已填写的字段的联系表单。我该怎么做呢? (正如您将在下面看到的,它目前用于不正确的验证码谷歌)

这是我的验证码。任何帮助都会很棒:

<?php require('sbsquared.class.php'); ?>
<?php
  require_once('recaptchalib.php');
  $privatekey = "myprivatekey";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    header("Location: http://www.google.com");  <--- this is the bit that I want to redisplay the form with fields already filled out.
  } else {

    $sb = New SBSquared;

    $name = $_POST['FullName'];
    $post_keys = array_keys($_POST);
    $my_db_string = "<table>";
    $ip_address = $_SERVER['REMOTE_ADDR'];
    foreach($post_keys as $field)
    {
        if($_POST[$field] != "" && $field != "submit_y" && $field != "submit_x" && $field != "submit_x")
        {

            $my_db_string .= "<tr><td><b>".$field.":</b></td><td>";
            if($field == "Email")
            {
                $my_db_string .= '<a href = "mailto:'.$_POST['Email'].'">'.$_POST['Email'].'</a>';
            }
            else
            {
                $my_db_string .= $_POST[$field];
            }

            $my_db_string .= "</td></tr>";

        }
    }

    $my_db_string .= "<tr><td><b>IP ADDRESS LOGGED: </b></td><td>".$ip_address."</td></tr>";

    $my_db_string .= "</table>";

    if(get_magic_quotes_gpc() != 1)
    {
        $my_db_string = addslashes($my_db_string);
        $name = addslashes($name);
    }

    $conn = $sb->openConnection();
    $dts = time();
    $sql = "INSERT INTO `contact_queries` VALUES ('', '$name', '$my_db_string', 'n/a', 0, $dts)";
    $result = mysql_query($sql, $conn) or die(mysql_error());

$content = '<div id="main_middle">';

$content .= '<span class="title">'.$sb->dt('Contact').'</span>
<p>'.$sb->dt('Thank you for your enquiry. We will contact you shortly.').'</p>


</div>';

// admin auto email.
        $dts = date("d.m.y h:ia", time());
        $admin_content = "New contact query at $dts";
        $admin_content .= "\n\n--\n\n \r\n\r\n";
        mail("email address", 'NOTIFICATION: new query', $admin_content, 'From: email address');
        $FILE=fopen("./log/auto-contact.txt","a");
        fwrite($FILE, $admin_content);
        fclose($FILE);

echo pageHeader($sb);
echo pageContent($sb, $content);
echo pageFooter($sb);
  }
?>

1 个答案:

答案 0 :(得分:0)

您可能已经为自己回答了这个问题,但如果没有,您可以在提交表单之前将ReCaptcha设置为进行验证,这与HTML5验证非常相似。在Captcha正确之前,它不会让用户提交。现在,我不知道它是否会刷新验证码,如果它是不正确的,但大多数时候我看到有人把它放入iFrame,所以刷新验证码时它不会刷新页面。

作为替代方案,您可以使用会话来保存数据。