将文本框文本插入 HTML 正文的 PHP 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5264963/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:48:34  来源:igfitidea点击:

PHP Code to Insert Text Box Text Into HTML Body

phphtml

提问by Will Evans

I am using the code below:

我正在使用下面的代码:

<form>
    <textarea cols="50" rows="4" name="link"></textarea>
    <textarea cols="50" rows="4" name="notes"></textarea>
    <input type="submit" value="Submit">
</form>

It creates two text boxes and I was wondering how to get them from this into a different html file's body code? I think I would need PHP.

它创建了两个文本框,我想知道如何将它们从这里转换为不同的 html 文件的正文代码?我想我需要PHP。

At the end I would just want it to display a message saying "Complete" and in a html file e.g code.html in the tags it would have the contents of the two text boxes seperated by one line.

最后,我只希望它显示一条消息,说“完成”,并在一个 html 文件中,例如 code.html 在标签中,它会将两个文本框的内容分隔为一行。

Regards!

问候!

回答by Kit

Sounds like you would need PHP to receive the data.

听起来您需要 PHP 来接收数据。

See thisfor a basic form that posts to a PHP page.

一个基本形式职位的PHP页面。

回答by MAG TOR

you most use php html like this:

你最常用的 php html 是这样的:

echo '<form id="form1" name="form1" method="post" action="">'.
'<p>PASWORD<br>'.
'<input type="text" name="name0" id="text" /><br><br>'.
'<p>BACKLINK<br>'.
'<input type="text" name="name" id="text" />'.
'<br>;'.
'<input type="submit" name="Enter" id="Enter" value="Enter" />'.
'</form>';

and use if for run html

并使用 if for run html

   if ($_POST['name0']>''){
      your code
     }

回答by Surreal Dreams

To accept input one one page and display it on another will require PHP. The general idea:

要接受一个页面的输入并将其显示在另一个页面上将需要 PHP。总体思路:

The HTML form page:Contains you HTML form where the user enters and submits their input. The data from the form is sent to the PHP processing script. We'll assume you use the POST method.

HTML 表单页面:包含用户输入和提交输入的 HTML 表单。表单中的数据被发送到 PHP 处理脚本。我们假设您使用 POST 方法。

The PHP processing script:Contains code to read the POST values and sanitize them. This means you want to check for HTML you don't want, script tags, etc - anything you don't want. In this case, the user will be displaying this code to themselves, so they can't really harm another user. However, it's something important to keep in mind. The rule of thumb - never trust user input- always check it and clean it. Now that the PHP script has read and cleaned the data, you want to display it.

PHP 处理脚本:包含用于读取 POST 值并对其进行清理的代码。这意味着您要检查您不想要的 HTML、脚本标签等 - 任何您不想要的。在这种情况下,用户将向自己显示此代码,因此他们不能真正伤害其他用户。但是,要记住这一点很重要。经验法则 -永远不要相信用户输入- 始终检查并清理它。现在 PHP 脚本已经读取并清理了数据,您想要显示它。

The PHP display script:Contains the HTML of the page and PHP code to display the values you captured in the PHP processing script.

PHP 显示脚本:包含页面的 HTML 和 PHP 代码,用于显示您在 PHP 处理脚本中捕获的值。

Other notes:The PHP processing and display scripts can live in the same file. You will have to process before you display. Alternately, you can run the processing script and then include the display script. Both will work.

其他注意事项:PHP 处理和显示脚本可以存在于同一个文件中。您必须在显示之前进行处理。或者,您可以运行处理脚本,然后包含显示脚本。两者都会起作用。