我正在使用 php 生成一个显示博客/线程项目的 html 页面,并且我正在使用 javascript 来显示/隐藏一些细节。问题是我正在为每组隐藏内容生成唯一 ID,其中包含处理输入的表单。在处理表单时,我需要知道编辑了哪个博客项目——我想使用 $_POST。我对javascript很陌生,我想可能有一个我可以在那里使用的解决方案。
我希望帖子将文本保存到 mysql 数据库(所以调用我正在工作的 php 函数之一)并告诉我文本是什么以及 threadId 是什么。
这是 php 代码片段,其中 $threadDetailItem 是一个数组,其中包含我的线程数据。
foreach ($threadData as $threadDetailItem)
{
// display main line (a bunch of code here ...)
// append button to edit or delete the post for admin
if ( isset ($_SESSION['isAdmin']) && $_SESSION['isAdmin'] == 'Y'){
// edit link opens content, and delete pops up a confirmation box
$el = sprintf ("editThreadLink_%d", $threadDetailItem['blogThreadId']);
$ec = sprintf ("editThreadContent_%d", $threadDetailItem['blogThreadId']);
$link1 = sprintf ("<a id=\"%s\" href=\"javascript:toggle('%s', '%s');\">+</a>", $el, $ec, $el);
$msg .= sprintf ("<li id=\"field6\">%s</li>\n", $link1);
}
$msg .= "</ul>\n";
echo $msg;
// now that the row is printed, lets add the hidden content if admin so they can edit
if ( isset ($_SESSION['isAdmin']) && $_SESSION['isAdmin'] == 'Y'){
// hidden content to enable editing of the posting
$msg = sprintf ("<div id=\"%s\" style=\"display: none\">\n", $ec);
echo $msg;
echo "<form name=\"form\" method=\"post\" action=\"\">\n";
$msg = sprintf ("<textarea id=\"%s\" name=\"%s\">%s</textarea>\n",
$ec, $ec, $threadDetailItem['threadTitle']);
echo $msg;
$msg = sprintf ("<button type=\"submit\"> %s</button>\n", $lang->get('BLOG POST'));
echo $msg;
echo "</form>\n";
echo "</div>";
}
}
非常感谢有关处理此事件的好方法的建议。提前致谢。
数据中的字段是:blogThreadId、threadTitle、username、createdOn、lastUpdated、displayed(未使用)和threadDetails(包含发布信息的数组)。