我有一个具有公共功能displayPosts的帖子:
public function displayPosts($numberOf = 50){
$result = $this->mysqlResult($this->id);
$i = 1;
while ($post = mysql_fetch_object($result)) {
$added = new Time;
$elapsed = $added->displayElapsedSignificant($post->data);
echo "
<h1>$post->title</h1>
<i>$elapsed</i>
<p>$post->text</p>
<h3>...komentarze...</h3>";
$this->displayComments($post->id);
"<hr />";
if($i == $numberOf) break;
else $i++;
}
}
私人功能displayComments:
private function displayComments($id){
$postComments = new Comments;
switch($this->getElement($id, "comment_type")){
case 1:
if($_POST) {
echo addSecurity($_POST['comment']);
}
else {
echo '
Zostaw komentarz:
<form action="#" method="post">
<textarea id="comment"></textarea><br />
<input type="submit" value=" Dodaj komentarz " />
</form>
';
}
break;
case 2:
//kod dla fb
break;
case 3:
//kod dla obu
break;
default:
break;
}
}
我的问题是表单不起作用:$ _POST始终为空。任何解决方案?
答案 0 :(得分:4)
您需要name
属性才能将表单值发送到服务器 - 如下所示:
<textarea id="comment" name="comment"></textarea>
$_POST
填充了name
(非id
)属性作为键和值作为值:)