繁体   English   中英

为什么我的表格不提交和重定向?

[英]Why does my form not submit and redirect?

我正在尝试将我们的网站迁移到使用PHP5的新主机。 以前,我们使用PHP4。

在用户填写之前在php4上工作过的调查后,我有一个不提交并重定向到thankyou页面的表单。 我敢肯定,我可能遗漏了一些明显的东西,但我看不出为什么它不起作用。

当我单击“提交”时,调查页面将重新加载,URL添加?submit = t到末尾,并且电子邮件没有发送给我。

下面显示了来自Survey.php的代码,其中包含我的电子邮件地址和大部分HTML表单字段。 有人可以指出我正确的方向吗?

谢谢!

  <?
$APP_ROOT = "../";
$FILE = __FILE__;
$TITLE="Service Survey";

if(!isset($submit)) {

    include($APP_ROOT."include/header.php");
    include($APP_ROOT."include/nava.php");
?>
<div class="bodymargin">
     <img src="<?=$WEB_ROOT;?>images/titles/<?=$SECTION."_".$FILE;?>.gif" width="400" height="36"><br>
    <br>
     <form method="POST" action="<?=$FILE;?>.php?submit=t">

<?
    if(isset($error)) {
        while(list($key, $value) = each($HTTP_GET_VARS)) {  
            $$key = stripslashes($value);
        }
        print("<p class=\"alert\">". urldecode($error) . "</p>\n"); 
    }
?> 
<input type="text" name="name" value="<?=$name;?>">
</form>

<?  
    include($APP_ROOT."include/navb.php");
    include($APP_ROOT."include/footer.php");
} else {
    include_once($APP_ROOT . "functions/index.php");
    include_once($APP_ROOT . "functions/form_validation.php");
    $CONTINUE = TRUE;


    $valid = new Validation($HTTP_POST_VARS);
    if($CONTINUE = $valid->success) {
        $to = "myemailaddress";
        $subject = "Service Survey";
        $from_email = $to;
        $from_name = "mysite.com";
        $headers = "From: $from_name<$from_email>\n"; 
        $headers .= "Reply-To: <$email>\n";
        $headers .= "Return-Path: <$from_email>\n"; 

        $body = "The following information was just posted \n";

        unset($HTTP_POST_VARS['required_fields']);
        reset($HTTP_POST_VARS);
        while(list($key, $value) = each($HTTP_POST_VARS)) {
            if(!empty($value)) {
                $body .= proper_form($key) . ":  " . stripslashes($value) ."\n";
            }   
        }
        $body .= "\nThis is an automated message, please do not respond.";
        mail($to,$subject,$body,$headers);
        $URL = $WEB_ROOT . "/customer/thanks.php?form=" . $FILE;
        server_redirector($URL);
    } else {
        while(list($key, $value) = each($HTTP_POST_VARS)) {
            $rebound .= "&$key=" . urlencode(stripslashes($value));
        }
        $URL = $WEB_ROOT . "customer/survey.php?error=". urlencode(nl2br($valid->errors)) . $rebound;
        server_redirector($URL);
        die();
    }
}
?>

regsiter_globals在较新的PHP版本中无效。 因此,必须使用if(!isset($_GET['submit']))而不是使用if(!isset($submit)) if(!isset($_GET['submit'])) 对于发布的值,可以使用$_POST['parameter']

__FILE__常量可能未返回您期望的结果,或者未返回其先前的结果。 文档

从PHP 4.0.2开始,__ FILE__始终包含已解析符号链接的绝对路径,而在旧版本中,在某些情况下,它包含相对路径。

因此,您现在可能会获得一条绝对路径,而不是相对路径。

还请按照文档中的说明检查新安装是否允许short_open_tags

$ HTTP_POST_VARS已弃用 您将要用$ _POST替换它。

或者,您可以仅添加$ HTTP_POST_VARS = $ _POST;。 在脚本的开头避免编辑每一行(不建议这样做)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM