如何将信息从表单发送到一段PHP代码,然后返回到文本区域?我找不到这个答案。PHP将文本发送到<input type =“text”>
回答
一个非常基本的例子。
假设你有一个名为index.php的
<?php
$val = 'Nothing in POST';
if (!empty($_POST)) { //$_POST is where stuff posted from the FORM is saved
$val = isset($_POST['text']) ? $_POST['text'] : '';//you're looking for the data with key text which is the name of your textarea element
$val = 'Got something from POST : ' . $val;
}
?>
<form action='index.php' method='post'>
<textarea name='text'><?php echo $val ?></textarea>
</form>
一个PHP文件,看看本教程为基础:http://net.tutsplus.com/articles/news/diving-into-php/
这就是我所说的,我想把两个值加在一起,并将我的结果发布到文本区域。 – daddycardona 2011-04-30 06:40:31
@daddycardona我更新了我的答案。这应该这样做 – JohnP 2011-04-30 06:43:02
是你这些教程是非常糟糕的屁股到目前为止感谢您的网站。 – daddycardona 2011-04-30 06:43:13
要打印出你在文本框输入的下一个请求文本应该是这样的假设您呈现相同的页面(即myform.php):
<?php
$fieldValue = htmlentities($_POST['myfield']);
?>
<form action="myform.php" method="post">
<label for="myfield">Your textfield:</label>
<input type="text" name="myfield" id="myfield" value="<?php echo $fieldValue; ?>" />
</form>
不要忘记用htmlspecialchars转义$ textfieldvalue – 2011-04-30 07:39:15
所以我不会把名字改为部分ID吗? – daddycardona 2011-04-30 11:06:59
@EmilVikström:是的,很好的指出,但我认为它已超出了给定问题的范围。 – stefanglase 2011-04-30 14:00:45
!用ajax(!和使用jquery对于AJAX)
假设你有这样的HTML:
<input type="text" id="input">
<textarea id="result"></textarea>
不是脚本应该是:
$('#input').keypress(function(e){
if(e.wich != 13)//not enter
return;
$.get(your_php_file.php,{param1:val1,param2:val2},function(result){
$('#result').val(result);
});
});
当你点击输入字段中输入,正在调用的ajax函数请求文件your_php_file.php?param1=val1¶m2=val2
。随着PHP的结果,回调函数被称为更新你的textarea
- 1. 增加<input type =“text”>
- 2. <input type =“text”/>换行
- 3. HTML <input type =“text”... as <input type =“file”
- 4. 拆分<input type =“text”>使用Angular.js
- 5. 另一个ASP:Textbox vs <input type =“text”>
- 6. 如何在<input type =“text”>标签内放置<input type =“file”>?
- 7. 如何将<input type =“image”>绑定到<input type =“text”>?两者都是相同的形式
- 8. <input type ='text'/>和<textarea>宽度
- 9. 如何使<span>高度与<input type =“text”>
- 10. <input type ='button'/>和<input type ='submit'/>之间的区别
- 11. 在<input type =“text”/>中输入文字描边
- 12. 如何使用Javascript在<input type =“text”>上填写文字<select>?
- 13. <input type =“text”> Splunk布尔操作符>
- 14. 转换明文到<INPUT TYPE =“文本”>
- 15. <button>与<INPUT TYPE =“图像”>
- 16. 如何将excel文件从<input type =“file”>上传到php服务器>
- 17. HTML5 <input type =“date”> change
- 18. 为<input type ='submit'>
- 19. <type =“input”runat =“server”>
- 20. 验证<input type =“date”>
- 21. input type =“text”not resizing
- 22. 是否可以通过dispatchEvent()将鼠标单击到<input type = text>元素?
- 23. 把默认值<INPUT TYPE =文件....>
- 24. 的Javascript:模拟<INPUT TYPE =“文件”>
- 25. <INPUT TYPE =“文件”>,改变价值
- 26. 如何获得“文”了<p>文本<INPUT TYPE =” ...的</p>
- 27. 将删除的文件添加到<input type =“file”多个>
- 28. jquery datepicker仅适用于Chrome中的<input type = text>?
- 29. 如何使用jQuery选择<input type =“text”>的值?
- 30. 如何动态创建<input type =“text”/>
你的问题是非常非常基本的。我的建议是遵循这个教程:http://net.tutsplus.com/articles/news/diving-into-php/它会非常有帮助 – JohnP 2011-04-30 06:29:03
@JohnP我知道,但我想要做的是显示我的导致一个文本框,但我读过或去过的所有基本教程都没有显示,他们只是说回声“要记录的东西”; – daddycardona 2011-04-30 06:34:06
增加了一个例子 – JohnP 2011-04-30 06:44:14