POST存储在隐藏字段中的数组索引的值


POST the value of an array index stored in hidden fields

我正在创建一个wordsearch,我试图在另一个页面中发布值,问题是我无法将$thisChar的所有值显示到另一个页面,我所得到的只是最后一个字母。问题是如何发布这样的变量例如,$rc[$r][$c]...

这是我的表格。我有一个名为thisChar的隐藏字段。

echo '<form method="post" action="#path" target="blank">';
echo '<table>';
    #--Display the random letters and the words
    for ($r=0;$r<=$row;$r++) {
        echo '<tr>';
        for ($c=0;$c<=$col;$c++) { 
            $thisChar=strtoupper($rc[$r][$c]); 
            echo '<input type="hidden" name="thisChar" value="'. $thisChar.'">';
               echo '<td  style="background:#fff">' . $thisChar . '</td>';
        }
               echo '</tr>';
 }
 echo '</table>';
 echo '<input type="submit" name="submit">';
 echo '</form>';

这就是我如何获取post数据。我得到的是未初始化偏移量错误

for ($r=0;$r<=$row;$r++) {
    for ($c=0;$c<=$col;$c++) { 
        $thisChar=$_POST['thisChar'];       
        $pdf->Cell(10,10, strtoupper($thisChar) ,1,0,'C', );    
    }       
}

我已经测试了其他方法,如foreach循环和在隐藏字段的名称上添加方括号,它工作,现在我想让它使用这种方法工作。此方法创建一个可以在表中显示的循环。知道怎么让它工作吗?

您需要将其作为数组发布,因此您的name属性应该像这样:

echo '<input type="hidden" name="thisChar[]" value="'. $thisChar.'">';

没有检查你的代码的其余部分,但这将发送所有的值作为一个数组

使用html输入名称作为数组!

echo '<input type="hidden" name="thisChar[]" value="'.$thisChar.'">';

然后在动作PHP文件中检索这个变量作为数组:

$thisChars=$_POST['thisChar'];
foreach($thisChars as $thisChar)
{
...
}