2015-10-30 233 views
0

我試圖從兩個不同的窗口將多個變量傳遞到相同的PHP腳本。這可能嗎?如果不是,最好的行動是什麼?試圖通過AJAX從多個窗口傳遞多個變量

感謝

verifyemail.html

<script type = "text/javascript" src = "js/js_functions.js"> </script> 
<form method="post" onsubmit = "return testAjax();" /> 
    <input type="email" placeholder="email" name="email" required maxlength = "50"><br> 
    <input type="email" placeholder="re-enter email"name="reemail" required maxlength = "50"><br>    
    <input type="submit" value="Verify Email"> 
</form> 

<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> 

signup.html:

<script type = "text/javascript" src="js/js_functions.js"></script> 
<form method="post" onsubmit="return ajaxTest();"/> 
      <input type="text" placeholder="username" name="username"  required = "required" maxlength = "15"><br> 
      <input type="password" placeholder="password" name="password" required = "required" pattern = "(?=.*\d)(?=.*[A-Z]).{10,}"><br> 
      <input type="password" placeholder="re-enter password"name="repassword" required = "required"><br> 
      <p class = "passwordreq">Password must:</p> 

      <input type="submit" value="sign up"> <input type="button" value="go back" onclick="window.location='index.html'"> 
     </form> 
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> 

js_functions

var username, password; 
function setUsrandPass(form) 
{ 
if(form.password.value != form.repassword.value) 
{ 
    alert("Passwords do not match"); 

} 

else { 
    username = form.username.value; 
    password = form.password.value; 

    window.location = 'verifyemail.html'; 

} 

return false; 
} 

function ajaxTest() 
{ 
if(form.email.value != form.reemail.value) 
{ 
    alert("Emails do not match"); 

} 

else 
$.ajax({ 
    type: 'GET', 
    url: 'signup_script.php', 
    data: {usr: username, pass: password, em: form.email.value}, 
}); 

return false; 
} 

php腳本:

<?php 

include 'profile_Functions.php'; 

$username = $_GET['usr']; 
$password = $_GET['pass']; 
$email = $_GET['em']; 

echo "got here!"; 

createUser($username,$password,$email); 
?> 
+1

你想同時提交兩頁的表格嗎?即在不同的標籤中打開? – Dhunt

+0

我想同時在php腳本中同時運行註冊和verifyemail的輸入 – jhell

+1

它們是否都顯示在一個頁面上? – Dhunt

回答

1

這是不可能的,從單獨的頁面的東西。他們需要向PHP腳本提出同樣的請求以提供這兩種數據。

您可以通過使用PHP寫入某種數據存儲區(即文件或數據庫)來避開此情況,然後等待另一個腳本寫入,然後PHP可以執行任何需要的處理。

+0

感謝您的幫助! – jhell