2009-06-25 71 views
0

file1.php,我執行file2.php文檔對象混亂

<form action="file2.php" method="POST"> 

在文件2,我想從文件1訪問HTML元素,但它們的文檔對象是不同的。

如何從file2中訪問file1的元素?

回答

1

好而不是使用JavaScript就可以訪問你通過PHP的$_POST功能所需要的,所以如果你有元素名和密碼,你可以用訪問它們:

$_POST['name']; 
$_POST['password']; 

所以像這樣的file2.php:

<?php 
    if(array_key_exists('submit', $_POST)) 
    { 
     $username = $_POST['name']; 
     $password = $_POST['password']; 

     echo("Hello $username, your password is $password"); 
    } 
?> 

這那張file1.php的假設看起來像:

<form action="file2.php" method="post"> 
    Username: 
    <input type="text" name="name" /> 
    <br /> 
    Password: 
    <input type="password" name="password" /> 
    <br /> 
    <input type="submit" name="submit" /> 
</form> 
+0

太棒了,這是我需要的答案! – wucnuc 2009-06-26 16:05:30

0

爲什麼你不試試在file2.php中隱藏你仍然需要的元素?

只需使用php在file2.php中再次渲染它們,並通過CSS隱藏它們,然後通過javascript輕鬆訪問它們。