简体   繁体   English

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

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

I am trying to migrate our site to a new host that uses PHP5. 我正在尝试将我们的网站迁移到使用PHP5的新主机。 Previously we were on PHP4. 以前,我们使用PHP4。

I have a form that is not submitting and redirecting to the thankyou page after a user fills out a survey which worked previously on php4. 在用户填写之前在php4上工作过的调查后,我有一个不提交并重定向到thankyou页面的表单。 I'm sure it's probably something obvious that I'm missing but I can't see why it doesn't work. 我敢肯定,我可能遗漏了一些明显的东西,但我看不出为什么它不起作用。

When I click submit, the survey page reloads, the URL gets ?submit=t added to the end and the email is not sent to me. 当我单击“提交”时,调查页面将重新加载,URL添加?submit = t到末尾,并且电子邮件没有发送给我。

The code from our survey.php is shown below with my email address and most of the HTML form feilds removed. 下面显示了来自Survey.php的代码,其中包含我的电子邮件地址和大部分HTML表单字段。 Can somebody point me in the right direction? 有人可以指出我正确的方向吗?

Thanks! 谢谢!

  <?
$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 is not active in newer PHP versions. regsiter_globals在较新的PHP版本中无效。 So instead of using if(!isset($submit)) you have to use if(!isset($_GET['submit'])) . 因此,必须使用if(!isset($_GET['submit']))而不是使用if(!isset($submit)) if(!isset($_GET['submit'])) And for posted values, you use $_POST['parameter'] . 对于发布的值,可以使用$_POST['parameter']

The __FILE__ constant is possibly not returning what you expect, or not what it previously did. __FILE__常量可能未返回您期望的结果,或者未返回其先前的结果。 from the docs 文档

Since PHP 4.0.2, __ FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances. 从PHP 4.0.2开始,__ FILE__始终包含已解析符号链接的绝对路径,而在旧版本中,在某些情况下,它包含相对路径。

So you may be getting an absolute path now, instead of a relative one. 因此,您现在可能会获得一条绝对路径,而不是相对路径。

Also check if your new installation allows for short_open_tags as explained in the docs 还请按照文档中的说明检查新安装是否允许short_open_tags

$HTTP_POST_VARS is deprecated . $ HTTP_POST_VARS已弃用 You will want to replace it with $_POST. 您将要用$ _POST替换它。

Alternatively, you can just add $HTTP_POST_VARS = $_POST; 或者,您可以仅添加$ HTTP_POST_VARS = $ _POST;。 at the beginning of the script to avoid editing every line (Not really recommended). 在脚本的开头避免编辑每一行(不建议这样做)。

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

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