我正在生成一个html表。每行均以“编辑按钮”开头。
网站A:
echo "<table border='1' align='center'>";
echo "<tr>"
. "<th style='font-weight:bold'></th>"
. "<th>".$nr.":</th>"
. "<th>Anschrift</th><th>Nachname</th>"
. "<th>Vorname</th>"
. " <th>PLZ</th>"
. "<th>Ort</th>"
. "</tr>";
echo "<form action='lxKundenEdit.php' method='POST'>";
$i=0;
foreach($arr as $key =>$value)
{
echo "<tr><td><input type='submit' name='btn'.$i.'\'' value='Bearbeiten'/></td>";
foreach($value as $subkey=>$subValue)
{
echo "<td>".$subValue."</td>";
}
echo "</tr>";
$i++;
}
echo "</form>";
echo "</table>";
然后我想知道哪个按钮被按下了。当邮寄POST-Array时,似乎没有任何作用。有什么提示吗?问候,伊斯米尔
网站B:
var_dump($_POST['btn0']); //f.e.
您需要做的是:
使所有以ID为键的提交按钮组成数组。
echo '<tr><td><input type="submit" name="btn[<?php echo $i;?>]" value="Bearbeiten"/></td>';
然后在PHP中,发布诸如以下的提交按钮:
if (! empty($_POST['btn']) {
foreach ($_POST['btn'] as $btnId => $btnVal) {
// $btnId is Id of the button that is $i
// $btnId means button is pressed.
// $btnVal is value of the button
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句