php 在php中将隐藏字段中的值从一页传递到另一页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8848180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
passing value in hidden field from one page to another in php
提问by rachel
I have a simple registration form. I want to pass value entered in one page to other in a text field. how to pass and access it from next page in php.
我有一个简单的注册表。我想将在一页中输入的值传递给文本字段中的另一页。如何从php的下一页传递和访问它。
this is my first php page.
这是我的第一个 php 页面。
Thanks in advance.
提前致谢。
回答by Paul Bain
You can add hidden fields within HTML and access them in PHP:
您可以在 HTML 中添加隐藏字段并在 PHP 中访问它们:
<input type="hidden" name="myFieldName" value="someValue"/>
Then in PHP:
然后在 PHP 中:
$val = $_POST['myFieldName'];
If you're going to ouput this again you should use htmlspecialchars
or something similar to prevent injection attacks.
如果你要再次输出它,你应该使用htmlspecialchars
或类似的东西来防止注入攻击。
<input type="hidden" name="myFieldName" value="<?=htmlspecialchars($_POST['myFieldName']);?>"/>
回答by mustafa
Suppose this the form input in page A
假设这是页面 A 中的表单输入
<form name="" action="" method=post enctype="multipart/form-data">
<input type="text" name="myvalue" value="">
<input type=submit>
</form>
In page B
在 B 页
In the page you want to get values put this code
在要获取值的页面中放置此代码
<?PHP
foreach ($_REQUEST as $key => $value ) {
$$key=(stripslashes($value));
}
?>
<form name="" action="" method=post enctype="multipart/form-data">
<input type="text" name="myvalue" value="<?PHP echo $myvalue" ?>">
<input type=submit>
</form>
So yo can use or attach variable value to another form do what else you want to do
所以你可以使用或附加变量值到另一个表单做你想做的其他事情
回答by vaibhav
use following code, that should help you.
使用以下代码,这应该对您有所帮助。
<form action ="formhandler.php" method ="POST" >
<input name = "inputfield" />
<input type="submit" />
</form>
on formhandler.php file yo need to enter following code to get the value of inputfiled.
在 formhandler.php 文件中,您需要输入以下代码以获取 inputfiled 的值。
$inputfield = isset($_POST['inputfield'])?$_POST['inputfield']:"";
// now you can do what ever you want with $inputfield value
echo($inputfield);