php 从文本区域获取输入并将其回显
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5262701/
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
Getting input from text area and echoing it out
提问by RSM
I have written some basic code so that a text area is displayed, and when the user inputs the text, clicks submit and it shows on the page in the method=''.
我已经编写了一些基本代码,以便显示一个文本区域,当用户输入文本时,单击提交并在页面上的 method='' 中显示。
The code i have for the form is :
我的表格代码是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Fun Translator</h1>
<form method="post" action="query.php">
<textarea name="txtarea">
</textarea>
<input type="submit" />
</form>
The code on the page query.php is:
页面 query.php 上的代码是:
<html>
<body>
<?php
echo $_POST["txtarea"];
?>
</body>
</html>
By looking at google, other questions and such, this should work, but doesnt!
通过查看谷歌,其他问题等,这应该有效,但没有!
Solution:
解决方案:
Thanks to Marc Audet, I put in phpinfo and all that came up in a big table as it does, I took it out and it started working. Any explanations?
多亏了 Marc Audet,我把 phpinfo 和所有出现在一个大表中的东西都放进去了,我把它拿出来,它开始工作了。有什么解释吗?
回答by madmik3
this code is perfectly fine. something else is going wrong.
这段代码非常好。其他事情出错了。
回答by user3079353
The textarea is not link to your form, you should add form="" in textarea like this:
textarea 不是链接到您的表单,您应该在 textarea 中添加 form="" ,如下所示:
<form method="post" action="query.php" name="myform">
<textarea name="txtarea" form="myform">
回答by user5624166
use
echo htmlspecialchars($_POST['name']);
to get value.
使用
echo htmlspecialchars($_POST['name']);
中获取价值。
回答by HymanJoe
some browsers like the ID...
一些浏览器喜欢ID...
add an ID like this:
添加一个像这样的ID:
<form method="post" action="query.php">
<textarea name="txtarea" id="txtarea">
</textarea>
<input type="submit" />
</form>
回答by Quentin
Best guess: Your server doesn't support PHP.
最佳猜测:您的服务器不支持 PHP。
Check the source code as delivered to the browser. If the <?php
bit shows up, then the server hasn't run the page through a PHP engine.
检查交付给浏览器的源代码。如果该<?php
位出现,则服务器尚未通过 PHP 引擎运行该页面。
回答by mgrantham18
As far as I know you should be doing textarea in the quotes not txtarea, I am not really sure though, it might be beneficial to use an ID instead.
据我所知,您应该在引号中而不是 txtarea 中使用 textarea,但我不确定,但使用 ID 可能会有所帮助。