无法在表单提交中存储会话变量

时间:2013-03-19 16:04:13

标签: php session

当我尝试将表单a提交到表单b并使用javascript window.open或者表单标记本身上的action =“”属性将其加载到新页面时,所有内容都会正确触发但在新页面上加载SESSION变量未传递。但是,如果我拿走window.open方法,提交表单并在我的浏览器中手动加载新页面,SESSION变量确实在新页面的输入字段中以表格b ...

正确显示

我想知道它是否与“return false”有关。我已经在表单上运行的onsubmit函数的一部分或者如果在表单提交和新页面加载时,它没有在SESSION存储它们之前设置SESSION值并将新页面加载到窗口中...它必须是那两个罪魁祸首。如果我不进行页面重定向,IT工作正常,所以我认为在提交后加载新页面时实际上并不存储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 FILE

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...");
            }
        });
    };

1 个答案:

答案 0 :(得分:3)

必须以

开头
<?php
session_start();
?>

你不能在html代码之后使用它