尝试在不离开html页面的情况下使用php进行动态html标签文本更改

问题描述 投票:0回答:1

我一直在尝试使用 php 对标签文本进行动态更改。无需离开html页面。因为大多数网站只使用 html。它尝试了一切,包括人工智能帮助。但我得到的只是错误,没有任何改变。另外,我的 echo 在浏览器中的 html 渲染上显示变量。 **$inputText";} ?> ** 我不知道为什么。我不太擅长 php,但我已经做了足够的工作让我的表单正常工作。我知道 PHP 是服务器端,但我以前见过它.我也试图避免添加js、json和jQuery。 enter image description here我已经尝试过形式: 并且此错误已停止:在此服务器上找不到请求的资源 /desktop/%3C?php%20echo%20$_SERVER[%27PHP_SELF%27];%20?%3E。

页面返回,但标签没有改变。有人可以给我一些帮助吗?这是我的代码:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Dynamic Label with PHP</title> </head> <body> <h1>Dynamic Label Example</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label for="input_text">Enter Text:</label> <input type="text" id="input_text" name="input_text" value=""> <input type="submit" value="Change Label"> </form> <?php // Check if form is submitted if(isset($_POST['input_text'])){ // Retrieve the input from the form $inputText = $_POST['input_text']; // Display the label with the new text echo "<label>$inputText</label>"; } ?> </body> </html>

我不太明白你所说的标签是什么意思。我想你指的是文字。
首先,你的合成不正确(请参阅我在你的问题中的评论)。
php html forms
1个回答
0
投票
我做了一个更改标签和文本的示例。选择你想要的。

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Dynamic Label with PHP</title> </head> <body> <h1>Dynamic Label Example</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <?php if(isset($_POST['input_text'])){ echo '<label>'.$_POST['input_text'].'</label>'; } else { echo '<label for="input_text">Enter Text:</label>'; } if(isset($_POST['input_text'])){ echo '<input type="text" id="input_text" name="input_text" value="'.$_POST['input_text'].'">'; } else { echo '<input type="text" id="input_text" name="input_text" value="">'; } ?> <input type="submit" value="Change Label"> </form> </body> </html>


© www.soinside.com 2019 - 2024. All rights reserved.