[英]POST when clicking button
So, I am trying to POST a variable to my controller when pressing a button (it will be created a button for each variable in a foreach
loop). 因此,我试图在按下按钮时将变量发布到控制器(它将为foreach
循环中的每个变量创建一个按钮)。
When pressing this button, I want to POST this variable, so I can request it in my controller. 按下此按钮时,我要发布此变量,因此可以在控制器中请求它。 When pressing this button, I also want my Modal to activate in the UI. 当按下此按钮时,我也希望我的Modal在UI中激活。
button (I use it now as a submit button). 按钮(我现在将其用作提交按钮)。
<form action="" method="post">
<button name="editUser" value="<?php echo $userResults['userID']; ?>"></button>
</form>
Later down in my view page, I also want to use the variable that was posted. 稍后在我的视图页面中,我也想使用发布的变量。
foreach ($userResults1 as $userResults1):
if (isset($_POST['editUser'])) {
$givenUserID = $_REQUEST["editUser"];
if ($userResults1['userID'] == $givenUserID) {
?>
<form action="?page=editUserEngine" method="post">
<input type="hidden" name="editUserID" value="<?php echo $userResults1['userID']; ?>"><br>
Navn: <br>
<input type="text" name="editName" value="<?php echo $userResults1['name']; ?>"><br>
Brukernavn: <br>
<input type="text" name="editUsername" value="<?php echo $userResults1['username']; ?>"><br>
Passord: <br>
<input type="text" name="editPassword" value="<?php echo $userResults1['password']; ?>"><br>
Brukernivå: <br>
<input type="text" name="editUserLevel" value="<?php echo $userResults1['userLevel']; ?>"><br>
Epost: <br>
<input type="text" name="editEmail" value="<?php echo $userResults1['email']; ?>"><br>
<br>
<input type="submit" value="Lagre">
</form>
<?php
}
}
endforeach;
In my Controller, i REQUEST the variables and pass it on to my Model: 在我的控制器中,我请求变量并将其传递给我的模型:
private function userEditEngine() {
$editUserID = $_REQUEST["editUserID"];
$editName = $_REQUEST["editName"];
$editUsername = $_REQUEST["editUsername"];
$editPassword = $_REQUEST["editPassword"];
$editUserLevel = $_REQUEST["editUserLevel"];
$editEmail = $_REQUEST["editEmail"];
$userEditInfo = $GLOBALS["userModel"];
$edited = $userEditInfo->editUser($editUserID, $editName, $editUsername, $editPassword, $editUserLevel, $editEmail);
header("Location:index.php?page=createUser");
}
This does work fine, but now I want to add a Modal, and display my form inn the Modal, but since I have to refresh the page to pass my variable with submit button, I kill the variable and my modal cant find it... 这确实可以正常工作,但是现在我想添加一个模态,并在模态中显示我的表单,但是由于我必须刷新页面以使用提交按钮传递变量,所以我杀死了该变量,但模态找不到它。 。
<td class="text-center">
<form id="brukerRedForm" action="" method="post">
</form>
<span data-toggle="modal" data-target="#brukerModal" type="submit">
<button form="brukerRedForm" type="button" name="editUsers" data-toggle="tooltip" title="Rediger bruker" value="<?php echo $userResults['userID']; ?>"
style="appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
outline: none;
border: 0;
background: transparent;
display: inline;">
<span class="glyphicon glyphicon-edit" style="color: green"></span></button>
</span>
I probably have to use Ajax, but I don't get it to work. 我可能必须使用Ajax,但是我无法使用它。 Anyone that have a suggestion? 有任何建议吗?
Well you can store the value of your variable in a session variable. 好了,您可以将变量的值存储在会话变量中。 For example: 例如:
session_start();
$_SESSION['editUser'] = $_POST['editUser'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.