0

我在这里要做的是向销售人员发送一封电子邮件,通知他们他们的客户已经查看了谷歌文档演示文稿。
查询的 Num=val 是一个序列号,我用来从数据库中获取实际的 google doc 的 url 并将其填充到表单中。

我的问题是页面在检索数据之前重定向,并最终转到该站点的默认值 nitrofill.com.index

gdform.php 文件具有标头重定向,如果我在页面加载时不尝试处理表单,它可以正常工作。继承人的代码:

<?php

$sn=$_GET['num'];
echo $sn;

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
 $selectSQL = "select * from `Presentations` where `serialnum` ='" . $sn ."'" ;

$result = mysql_query($selectSQL) or die(mysql_error());
$row = mysql_fetch_array($result,  MYSQL_BOTH);


?>

<script type="text/javascript">
function myfunc () {
var frm = document.getElementById("notice");
frm.submit();
}
window.onload = myfunc;
</script>

<title>Nitrofill Document</title></head>
<body>
 <form id="notice" action="http://m3sglobal.com/gdform.php" method="post"> 
  <input type="hidden" name="subject" value="<?php echo (urldecode($row['recipient'])) . " has viewed the document you sent them."; ?>" /> 
<input type="hidden" name="redirect" value="<?php echo ((urldecode($row['docurl']))); ?>"/>
<label>Email:</label><input type="text" name="email" value="<?php echo (urldecode($row['tracker'])); ?>"/>
<label>Comments:</label><textarea name="comments" cols="40" rows="5">
Document Viewed:<?php echo ((urldecode($row['docurl']))); ?>

When Accessed:<?php echo ((urldecode($row['last_accessed']))); ?>
</textarea>
<input type="submit" name="submit"/>
</form>

gdform.php 像这样进行重定向:

  while (list ($key, $val) = each ($query_vars)) {
     fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\n");
     fputs($fp,"$val\n");
     fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\n");
     if ($key == "redirect") { $landing_page = $val;}
    }
    fclose($fp);
     if ($landing_page != ""){
    header("Location: "  . $landing_page);
    } else {
    header("Location: http://".$_SERVER["HTTP_HOST"]."/");
    }

感谢您的关注!

4

1 回答 1

0

HTML 中的代码是自上而下执行的。一旦你到达那个 JavaScript 块,你就提交了,甚至在你在页面上呈现表单之前。

将你的 JS 代码移动到页面底部,或者在 DOM 准备好之后执行它。

于 2012-02-23T19:29:17.067 回答