使用POST将数据从一个textarea传递到另一个页面上的另一个textarea [英] Passing data from one textarea to another on a different page using POST

查看:111
本文介绍了使用POST将数据从一个textarea传递到另一个页面上的另一个textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将数据从一个textarea传递到另一个页面上的另一个textarea的问题。我使用PHP POST函数来从第一页中检索数据。另外,在JSON和PHP与MySQL数据库交谈的帮助下,我有JavaScript将数据插入第一页的textarea。

I have a problem of passing data from one textarea to another textarea on another page. I’m using php POST function in order to retrieve data from the first page. Also, I have JavaScript inserting data into the textarea on the first page with the help of JSON and PHP talking to MySQL database. Inserting data into textarea from the database on the first page works.

当我点击第一页上的提交按钮时,没有数据被传递到第二页。非常感谢您的帮助。

When I click on the submit button on the first page, no data is passed to the second page. Many thanks for your help.

Page 1
-----------------------------------------------------------------------------------------
<form action="page2.php" method="post" id="role" name="roleForm">
<fieldset id="fieldset">
<legend id="legend">Background</legend>
<p>
  <label for="background"></label>
  <textarea name="background" cols="71" rows="10" id="backgroundtext">
</textarea></p>
</fieldset>
<br></br>
<p><input type="submit" name="Submit" value="Add role to job description" id="addjobdesc" /></p>
</form>


JavaScript file (part of the file)
---------------------------------------------------------------------------------------
function set_background (newValue)
{
    var field = document.roleForm.backgroundtext;
    field.value = newValue;
}



page2.php
-------------------------------------------------------------------------------------------
<fieldset id="fieldset">
<legend id="legend">Background</legend>
<p>
  <label for="background2"></label>
  <textarea name="background2" cols="71" rows="10" id="backgroundtext2" value="<?php echo $_POST["background"]; ?>"/>     
</textarea></p>
</fieldset>
<br></br>


推荐答案

您必须编写textarea的内容BETWEEN

You have to write the content of the textarea BETWEEN the tags, not into a value attribute:

<textarea name="background2" cols="71" rows="10" id="backgroundtext2">
<?php echo $_POST["background"]; ?></textarea>

请注意,此代码极度不安全!如果$ _POST [background]包含HTML,它将压低你的html代码等。

Be aware that this code is extremly unsafe! If the $_POST["background"] contains HTML it will be brake down your html-code etc.

这篇关于使用POST将数据从一个textarea传递到另一个页面上的另一个textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆