我正在尝试创建一个页面,其中有几个字段和用户可以评论每一个。为了创建这些字段和文本输入,我运行了一个while循环,其中包含以下html:
<form name = "replyform" method = "post" action = "">
<input id = "replytext<? echo $replyID; ?>" value = "replytext<? echo $replyID; ?>" name = "replytext<? echo $replyID; ?>" type="text" class = "span5">
</form>
然后使用下面的代码调用'wall_reply()'函数,提交文本值。
if (isset($_POST['replytext'.$replyID])) {
echo wall_reply();//5, $_POST['replytext'.$replyID]);
}
不过有些东西没打中。你知道这里有什么问题吗?
你有循环创建这些表单和输入吗?
将循环放入表单标记中,这样只会创建一个包含多个输入的表单。
这似乎工作正确,使用它作为您的指导;)
<?php
$maxposts=7;
if (isset($_POST['submit'])){
function wall_reply($id,$text){
echo '<hr />updating id '.$id.' with '.$text;
}
var_dump($_POST);
for ($i=0;$i<$maxposts;$i++){
$replyID = $i;
if (isset($_POST['replytext'.$replyID])) {
wall_reply($i,$_POST['replytext'.$replyID]);//5, $_POST['replytext'.$replyID]);
} else {
echo 'not set';
}
}
}
?>
<form name = "replyform" method = "post" action = "">
<?php
$replyID = 5;
for ($i=0;$i<$maxposts;$i++):
$replyID = $i;
?>
<input id = "replytext<?php echo $replyID; ?>" value = "replytext<?php echo $replyID; ?>" name = "$
<?php endfor; ?>
<input type="submit" name="submit" value="go"/>
</form>