2013-03-19 78 views
1

當我嘗試將表單a提交給表單b並使用javascript window.open或者表單標記本身的action =「」屬性將其加載到新頁面時,關閉正確,但在新的頁面加載SESSION變量不傳遞。但是,如果我拿走了window.open方法,提交表單並手動加載我的瀏覽器中的新頁面,SESSION變量在窗體b的新頁面上的輸入字段中確實出現...無法在表單提交中存儲會話變量

I想知道這與「回報錯誤」有什麼關係?部分onsubmit函數我運行在form上,或者如果在表單提交和新的頁面加載時,它不會在SESSION存儲它們並將新頁面加載到窗口之前設置SESSION值......它必須是那兩個匪徒。如果我不做一個頁面重定向,它的工作原理,所以我相信它實際上不是在提交後加載新頁面時存儲SESSION變量......我如何正確和成功地將SESSION存儲在新頁面加載中,以便加載正確地在form b上的新頁面中?

索引文件(FORM 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..."); 
      } 
     }); 
    }; 

回答

3

必須啓動文件,

<?php 
session_start(); 
?> 

HTML代碼

+0

我之後,你不能用它編輯我的帖子...我在服務器上的文件中正確,我正確在這篇文章中錯誤地指出了它。此外,除非實際上必須在表單提交中加載新頁面,否則它全部正常工作,但無論如何感謝您的快速回復。 – jflay 2013-03-19 16:06:52

+0

返回false似乎是目前的罪魁禍首...有沒有更好的方法來運行函數uploaddata();所以它正確啓動? – jflay 2013-03-19 16:17:26

+0

不需要'返回false'。你可以刪除它。 – 2013-03-19 16:24:14