Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将文本框从一页转移到另一页_Php_Input_Textbox - Fatal编程技术网

Php 如何将文本框从一页转移到另一页

Php 如何将文本框从一页转移到另一页,php,input,textbox,Php,Input,Textbox,我是php新手,需要一些帮助 我有两个网站。我想在index.php上显示我的edit.php中的文本框。 <form method="post"> <textarea name="content" cols="40" rows="5"> Enter your comments here... </textarea><br> <input type="submit

我是php新手,需要一些帮助

我有两个网站。我想在index.php上显示我的edit.php中的文本框。

        <form method="post">
        <textarea name="content" cols="40" rows="5">
        Enter your comments here...
        </textarea><br>
        <input type="submit" value="Submit" />
        </form>
          <?php
       $content = $_POST["content"];?>

在这里输入您的评论。。。


如何将变量$content传输到我的索引页面?

好的,只需将表单上的操作设置为您希望它发布到的页面-示例:

随机页面:

    <form method="post" action="/index.php">
    <textarea name="content" cols="40" rows="5">
    Enter your comments here...
    </textarea><br>
    <input type="submit" value="Submit" />
    </form>
至少我认为这是你要问的


如果要将随机文本框回显到页面,请确保使用
htmlspecialchars()

对其进行清理,并尝试将表单移动到index.php:

<form method="post" action="/index.php">
</form>

这样,一旦您提交表单,您的页面index.php将被加载,表单的值将显示在$\u POST中。

//在您的编辑页面上
// on your edit page
<form method="post" action="index.php">
<textarea name="content"></textarea>
<input type="submit" />
</form>

// on your index page
if( $_SERVER['REQUEST_METHOD'] == 'POST' ){ // This will prevent the textarea from
     // being shown unless some form posted to this page
    echo '<form method="post">
    <textarea name="content">'.$_POST['content'].'</textarea>
    <input type="submit" />
    </form>';
     // If it's not set or it's empty, then it just won't show anything....
     // you don't need to check for that unless you want to set a value when it is empty
}
//在您的索引页上 如果($\u服务器['REQUEST\u METHOD']='POST'){//这将阻止textarea //正在显示,除非某些表单已发布到此页面 回声' “.$”发布[“内容]。” '; //如果未设置或为空,则不会显示任何内容。。。。 //您不需要检查它,除非您想在它为空时设置一个值 }
在编辑中,您希望确保您的操作指向index.php

<?php echo $_POST["myTextBox"] ?>
<form method="post" action="index.php">
    <textarea name="myTextBox" cols="40" rows="5"><?php echo htmlentities($_POST["myTextBox"]); ?></textarea>
    <input type="submit" value="Submit" />
</form>
edit.php

<form method="post" action="index.php">
    <textarea name="myTextBox" cols="40" rows="5"></textarea>
    <input type="submit" value="Submit" />
</form>

在index.php中,您可以使用$_POST[“myTextBox”]访问变量,在下面的示例中,该变量可以作为文本或值输出。确保在表单字段中包含值时使用htmlentities,这将防止“注入黑客”。 index.php

<?php echo $_POST["myTextBox"] ?>
<form method="post" action="index.php">
    <textarea name="myTextBox" cols="40" rows="5"><?php echo htmlentities($_POST["myTextBox"]); ?></textarea>
    <input type="submit" value="Submit" />
</form>

只需将表单更改为发布到第二个站点而不是自身,然后在index.php页面上回显$\u post['content']

www.firstsite.com/edit.php

<form action="www.secondsite.com/index.php" method="post">
  <ul>
    <li>
      <textarea name="content" cols="40" rows="5">Enter your comments here...</textarea>
    </li>
    <li class="submit">
      <input type="submit" value="Submit" />
    </li>
  </ul>
</form>
<?php echo $_POST['content']; ?>

  • 在这里输入您的评论。。。
www.secondsite.com/index.php

<form action="www.secondsite.com/index.php" method="post">
  <ul>
    <li>
      <textarea name="content" cols="40" rows="5">Enter your comments here...</textarea>
    </li>
    <li class="submit">
      <input type="submit" value="Submit" />
    </li>
  </ul>
</form>
<?php echo $_POST['content']; ?>

来回应您的评论。(不要贬低我……他最初的问题并不准确)

//在编辑页面上
//当您提交编辑页面时
$filename='/mytextarea.txt';
$content=file\u put\u contents($filename,$\u POST['content']);
//在您的索引页上
$filename='/mytextarea.txt';
$content=file\u get\u contents($filename);
如果(!空($content)){
回显“.$content.”;
}

当我直接连接index.php时,我需要搜索在edit.php中键入的内容。即使我没有在本次会话中放入一些内容,在这种情况下,您必须将表单post的结果保存到数据库或文本文件中,然后将保存的数据拉入索引。phpI需要将文本从编辑页面放到我的索引页面中的div中。。。因此,它应该看起来像索引页面上的普通文本,您只需将$_POST['content']封装为而不是tnxxxx,这就是我所要求的解决方案。再来一次!