我想从另一个(ModifyUsers.php
)召唤一个PHP页面(RumpUserAdministration.php
)。我试图将其作为单独的页面召唤,而不是作为“用户管理”页面的子部分,并使用POST从userID
传递给RumpUserAdministration.php
ModifyUsers.php
。
我添加了alert
个语句,这些语句显示userID
在召唤修改用户页面之前就存储在hidden-id-field
内,因此可用于POST,但它不是转移到“修改用户”页面。
我还添加了alert
个语句,指出在执行页面的那些点上使用了哪种服务器请求方法。我页面上的其他按钮同样需要召唤其他页面。
我的问题是:如何使用POST召唤我的“修改用户”页面,以便我可以使用POST传输我的值?
我能够同时使用GET和SESSION变量,但这个特殊情况主要集中在POST - GET和SESSION变量不被使用。
我已经就这个问题咨询了我的同学和所有讲师,并在寻找解决方案的过程中浏览了20多个不同的网站和多个搜索。所提出的所有“解决方案”都没有被证明是完全有效的 - 人们现在和我一样陷入困境,网页使用的方法只适用于更新源页面,而不是召唤新的或者只是错误。< / p>
以下是我一直用于解决此问题的文件。
RumpUserAdministration.php
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport"
content = "width=device-width, initial-scale=1.0"
>
<meta charset = "utf-8">
<link href = "CSS/RumpIntranetProject.css"
rel = "stylesheet"
type = "text/css"
>
</head>
<body>
<?php
echo "<script>alert( \"" . $_SERVER[ "REQUEST_METHOD" ] . "\" )</script>";
?>
<form id = "entire-page"
action = "RumpUserAdministration.php"
method = "post"
>
<div id = "user-name-list-section">
<div id = "user-name-list">
<div id = "ID15"
class = "list-item row"
name = "ID15"
onclick = "userNameListItemClicked( '15' )"
>
SAMPLE USER 001
</div>
<div id = "ID16"
class = "list-item row"
name = "ID16"
onclick = "userNameListItemClicked( '16' )"
>
SAMPLE USER 002
</div>
</div>
</div>
<input id = "user-administration-button-delete"
name = "delete-submit"
onclick = "loadDeleteUsers()"
type = "submit"
value = "Delete"
>
<input id = "user-administration-button-modify"
name = "modify-submit"
onclick = "loadModifyUsers()"
type = "submit"
value = "Modify"
>
<input id = 'hidden-id-field'
name = 'userID'
type = 'hidden'
value = ''
>
</form>
<?php
if ( $_SERVER[ "REQUEST_METHOD" ] == "POST" )
{
if ( isset( $_POST[ 'modify-submit' ] ) )
{
echo "<script>document.getElementById( 'hidden-id-field' ).value = \"" . $_POST[ 'userID' ] . "\"</script>";
echo "<script>alert( \"hidden-id-field (userID) : \" + document.getElementById( 'hidden-id-field' ).value )</script>";
echo "<script>alert( \"" . $_SERVER[ "REQUEST_METHOD" ] . "\" )</script>";
echo '<script>window.location = "ModifyUsers.php"</script>';
}
else
{
echo "<script>alert( 'Unexpected Administration POST encountered.' )</script>";
}
}
?>
<script>
var existingSelection = null;
function loadModifyUsers()
{
document.getElementById( 'hidden-id-field' ).value = existingSelection;
alert( "Presubmit" );
document.getElementById( 'entire-page' ).submit;
}
function userNameListItemClicked( userID )
{
existingSelection = 'ID' + userID;
document.getElementById( "user-administration-button-modify" ).style.cursor = "pointer";
document.getElementById( "user-administration-button-modify" ).disabled = false;
}
</script>
</body>
</html>
ModifyUsers.php
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport"
content = "width=device-width, initial-scale=1.0"
>
<meta charset = "utf-8">
<link href = "CSS/RumpIntranetProject.css"
rel = "stylesheet"
type = "text/css"
>
</head>
<body>
<?php
echo "<script>alert( 'In further' )</script>";
echo "<script>alert( \"hidden-id-field (userID) : \" + document.getElementById( 'hidden-id-field' ).value )</script>";
echo "<script>alert( \"userID : \" + \"" . $_POST[ 'userID' ] . "\" )</script>";
?>
</body>
</html>
RumpIntranetProject.css
html,
*
{
border : 0;
box-sizing : border-box;
margin : 0;
padding : 0;
}
.list-item
{
display : block;
}
.list-item:hover
{
background-color : #00ffff;
}
.row:after
{
clear : both;
content : "";
display : block;
}
#user-name-list
{
border : 1px;
border-color : black;
border-style : solid;
overflow-y : scroll;
width : 300px;
}
我不确定这个问题是由于错过了include
,错字,错误命令还是其他任何一个,我不知道错误在哪里。因此,为了完整性,我必须包括每个最小化文件的全部内容。我正在研究我对“最小”的定义。 :)
答案 0 :(得分:2)
看起来您正在使用JavaScript来更改页面:
echo '<script>window.location = "ModifyUsers.php"</script>';
你在这里做什么是加载ModifyUsers.php
,但是[因为这是一个GET]没有任何东西可以通过POST传递。
您需要做的是将表单的action
更改为ModifyUsers.php
:这样您的POST数据就会传递到正确的页面。
答案 1 :(得分:0)
这是我刚刚开发的一个答案。如果有其他方式回答问题,请发布。
我已将每个“提交”按钮放在其自己的表单中,包括每个表单中的隐藏字段。
这些按钮中的每一个都成功地传唤了它的形式,而不是其他东西。
以下是我使用的RumpUserAdministration.php的修改版本(ModifyUsers.php和RumpIntranetProject.css与问题相同)。
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport"
content = "width=device-width, initial-scale=1.0"
>
<meta charset = "utf-8">
<link href = "CSS/RumpIntranetProject.css"
rel = "stylesheet"
type = "text/css"
>
</head>
<body>
<?php
echo "<script>alert( \"" . $_SERVER[ "REQUEST_METHOD" ] . "\" )</script>";
?>
<div id = "user-name-list-section">
<div id = "user-name-list">
<div id = "ID15"
class = "list-item row"
name = "ID15"
onclick = "userNameListItemClicked( '15' )"
>
SAMPLE USER 001
</div>
<div id = "ID16"
class = "list-item row"
name = "ID16"
onclick = "userNameListItemClicked( '16' )"
>
SAMPLE USER 002
</div>
</div>
</div>
<form id = "form-delete"
action = "Index.php"
method = "post"
>
<input id = 'hidden-id-field-delete'
name = 'userID'
type = 'hidden'
value = ''
>
<input id = "user-administration-button-delete"
name = "delete-submit"
onclick = "loadDeleteUsers()"
type = "submit"
value = "Delete"
>
</form>
<form id = "form-modify"
action = "ModifyUsers.php"
method = "post"
>
<input id = 'hidden-id-field-modify'
name = 'userID'
type = 'hidden'
value = ''
>
<input id = "user-administration-button-modify"
name = "modify-submit"
onclick = "loadModifyUsers()"
type = "submit"
value = "Modify"
>
</form>
<script>
var existingSelection = null;
function loadDeleteUsers()
{
document.getElementById( 'hidden-id-field-delete' ).value = existingSelection;
}
function loadModifyUsers()
{
document.getElementById( 'hidden-id-field-modify' ).value = existingSelection;
}
function userNameListItemClicked( userID )
{
existingSelection = 'ID' + userID;
document.getElementById( "user-administration-button-modify" ).style.cursor = "pointer";
document.getElementById( "user-administration-button-modify" ).disabled = false;
}
</script>
</body>
</html>