【发布时间】:2015-07-17 12:41:32
【问题描述】:
花了两天多的时间寻找这个难题的答案,我现在直接发布这个问题。 有很多提示和答案,但没有一个能明确解决我面临的问题,因此发布了这篇文章。
我有一个特定问题的以下脚本, 我无法将 textarea 的内容传递给另一个 php 文件,该文件通过触发创建动态表单的 href 激活。
这个概念是:
有一个变量:“评论”
通过接受文本并将其存储到变量“comment”中的表单传递文本区域。
然后,当用户单击<a href="hsl:logcall?... 超链接时,该链接将传递到数据库中的 updatedb.updatetxt 表。
可以获取要传递的设置文本,但不是基于文本区域信息的变量...
这是 html/php 代码:
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
// define variables and set to empty values
$comment = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["comment"])) {
$comment = "";
} else {
$comment = test_input($_POST["comment"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<TABLE CELLSPACING="10">
<TR>
<TD>
<TABLE>
<TR>
<TD>
<p>
<b>Please use the below to start capturing your Call Description:</b>
<form method="POST">
<textarea name="comment" id="comment" rows="5" cols="45"></textarea>
</form>
</TD>
<TR>
<TD>
<?php
$comment = $_POST[comment]; // Variable who accept your data from textarea
// You don't need to use variables, but if you starter, easier to understand.
// Do something with your arrived data...
// Stupid, but for short explanation... for example echo it...
echo $comment;
?>
<a href="hsl:editrecord?formmode=edit&table=userdb&key=<?=$userdb_keysearch;?>"><img src="img/icons/call_update.gif" width="16" height="16" alt="" border="0" />Edit Details</a>
<a href="hsl:logcall?userdb.keysearch=<?=$userdb_keysearch;?>&updatedb.updatetxt=<?=($_POST[comment]);?>"><img src="img/icons/call_detail.gif" width="16" height="16" alt="" border="0" />Log New Call</a>
<a href="hsl:printme"><img src="img/icons/call_print.gif" width="16" height="16" alt="" border="0" />Print This Page</a>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</body>
</html>
这是未经编辑的原始代码
<a href="hsl:editrecord?formmode=edit&table=userdb&key=<?=$userdb_keysearch;?>">
<img src="img/icons/call_update.gif" width="16" height="16" alt="" border="0" />Edit Details</a>
<a href="hsl:logcall?userdb.keysearch=<?=$userdb_keysearch;?>">
<img src="img/icons/call_detail.gif" width="16" height="16" alt="" border="0" />Log New Call</a>
<a href="hsl:printme"><img src="img/icons/call_print.gif" width="16" height="16" alt="" border="0" />Print This Page</a>
【问题讨论】:
-
html 不是你的朋友吗?请检查您的 html 代码
-
自 1999 年以来没有人用大写 HTML 编写...
-
危险:此代码为vulnerable to XSS。用户输入在插入 HTML 文档之前需要转义!
-
stripslashes($data);可能会破坏您的数据,除非您打开了魔术引号(您不应该这样做)。 -
您的 HTML 无效。使用验证器:validator.w3.org/nu
标签: javascript php jquery html css