1

当我尝试将表单 a 提交到表单 b 并使用 javascript window.open 或表单标签本身的 action="" 属性将其加载到新页面时,一切都会正确触发,但在新页面上加载 SESSION 变量没有通过。但是,如果我取消 window.open 方法,提交表单并在浏览器中手动加载新页面,则 SESSION 变量确实会在表单 b 的新页面的输入字段中正确显示...

我想知道它是否与“return false”有关;我在表单a上运行的onsubmit函数的一部分,或者如果在表单提交和新页面加载时,它没有在SESSION存储它们并将新页面加载到窗口之前设置SESSION值......它必须是其中之一那两个罪魁祸首。如果我不进行页面重定向,它就可以工作,所以我相信在提交后加载新页面时它实际上并没有存储 SESSION 变量......我怎样才能正确并成功地在新页面加载时存储 SESSION 以便它加载在表格 b 的新页面中正确吗?

索引文件(表格 A)

<?php
session_start();
if(isset($_POST['submit'])) {
    $_SESSION['cable_no'] = $_POST['cable_no'];
    $_SESSION['co_name'] = $_POST['co_name'];
    $_SESSION['prepping_team'] = $_POST['prepping_team'];
    $_SESSION['section_no'] = $_POST['section_no'];
    $_SESSION['tech_name_a'] = $_POST['tech_name_a'];
}
?>
<header>
<script type="text/javascript" language="javascript" src="/jquery/js/jquery-1.9.1.js">       </script>
<script type="text/javascript" language="javascript" src="js/scripts.js"></script>
<link href="css/style.css" type="text/css" rel="stylesheet" />
</header>
<form method="post" onsubmit="uploaddata(); return false;">
HTML CODE
<input type="submit" id="submit" name="submit" value="Continue" />
</form>

JS文件

function uploaddata() { 

//Read all of the data from the page
for (eID in prepform) {
    prepform[eID] = document.getElementById(eID).value;
}
//Send to database upload function and verify IF checkboxes are checked
if(document.getElementById("a11").checked && document.getElementById("b11").checked && document.getElementById("c11").checked && document.getElementById("a12").checked && document.getElementById("b12").checked && document.getElementById("c12").checked) {
        upload_prepform();
    }else{
        alert("Please verify that you have checked the known check boxes.")
    }
}   
function upload_prepform() {
    $.ajax({
            type: 'POST',
            url: './php/upload_prepform.php',
            data: prepform,
            async: false,
            dataType: 'text',
            success: function() {
                alert("Thank you. Your Prep form has been submitted.");
            },

            error: function(jqXHR, textStatus, errorThrown) {
                    alert("Error... " + textStatus + "\n" + errorThrown);
            },
            complete: function() {
                window.location.replace("http://dev1.rs.idmyasset.com/gp21-dev/prep_b/");
                alert("Redirecting...");
            }
        });
    };
4

1 回答 1

3

必须以文件开头

<?php
session_start();
?>

html代码后不能使用

于 2013-03-19T16:05:37.337 回答