简体   繁体   English

我可以将html文本字段值设置为变量,以便保存以前输入的内容吗?

[英]Can I set an html text field value to a variable, so it saves the previously entered content?

<?php $content = $_POST['content']?> <p>Page title: <input type='text' name='title' value="<?php $content ?>"/></p> <?php $content = $_POST['content']?> <p>Page title: <input type='text' name='title' value="<?php $content ?>"/></p>

I would like to know if something like this is either possible, or if theres a work around, like a way to save the previously entered content as the value. 我想知道这样的事情是否可行,或者是否可以解决,比如将以前输入的内容保存为值的方法。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

Save it in a session and retrieve it anywhere using the key just start the session like below : 将它保存在会话中并使用密钥在任何地方检索它,只需启动会话,如下所示:

<?php
// Start the session
session_start();
?>

<?php
// Set session variables
$content = $_POST['content']
$_SESSION["content"] = $content;

echo "Session variables are set."+ $_SESSION["content"] ;
?>

If you want to do it with PHP you need to learn about sessions and cookies . 如果你想用PHP做,你需要了解会话cookie

Here is an example with cookies 这是一个cookie的例子

<?php
start_session();
if(isset($_GET["title"])) {
    if(isset($_SESSION["oldTitle"])) {
        // do what you want to do
    }
    // update to the new value
    $_SESSION["oldTitle"] = $_GET["title"];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用变量设置文本输入字段的值吗? - Can I Set The Value Of A Text Input Field Using A Variable? 在输入文本中输入值后,如何将html内容转换为ms字? - How to convert html content to ms word after I entered value in input text? 我如何验证$ value,如果输入&#39;0&#39;则通过? - How can I validate $value so it passes if a '0' is entered? 如何检查在表单字段中输入的值是数字? - How can I check a value entered in a field on my form is a number? 我如何将变量从PHP传递到我的html文本,以便它根据值而变化 - how do i pass a variable from PHP to my html text ,so that it changes depending on the value 如何让我的PHP脚本验证在HTML表单上输入的内容,以便仅显示在该表单上输入的内容? - How can I have my PHP script validate what was entered on my HTML form so that it will only display what was entered on that form? 如何使用先前输入的值填充自定义结帐字段,例如默认的 WooCommerce 结帐字段? - How to fill custom checkout field with previously entered value, like default WooCommerce checkout fields? 使用Javascript将PHP变量设置为HTML文本字段的值 - Using Javascript for setting PHP variable as HTML text field's value 设置一个等于变量的函数,这样我就可以做到这一点($ var) - set a function equal to a variable so i can do this($var) PHP:如何将用户在文本字段中输入的数据发送到txt文件? - PHP:How can I send the Data entered by a user in a text field to a txt file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM