php-动态创建的单选按钮句柄


php- dynamically created radio buttons handle

所以。。我有一个上传页面,可以上传一个充满数据的xml表。im在页面本身处理它(不将它发送到任何数据库-在页面关闭后将其擦除(我不知道每次会上传多少行,但假设不会超过100行。

现在,我得到了这个部分,作为一个上传所有数据的表单,用户需要在为每行创建的单选按钮中选择一个值(单选按钮的值:1-5(:

<form enctype="multipart/form-data" name="myForm" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" onsubmit="return checkForm()">
    <?php $numRow=0;?>
    <?php //echo "<input type='radio' name='difficulty".$numRow."' value='11'>11";?>
    <table border="1">
        <tr> 
            <th>table of all courses</th> 
        </tr> 
        <?php $data[0]['Points']="נז";?>
        <?php foreach( $data as $row ) { ?> 
        <tr> 
            <td><?php echo( $row['Year'] ); ?></td>
            <td><?php echo( $row['Semester'] ); ?></td>
            <td><?php echo( $row['Code'] ); ?></td>   
            <td><?php echo( $row['Course'] ); ?></td> 
            <td><?php echo( $row['Points'] ); ?></td> 
            <td><?php echo( $row['Grade'] ); ?></td>
            <td><?php if ($numRow > 0)
                    {
                        for($choise=1;  $choise<6;  $choise++)
                        {
                            echo "<input type='radio' name='difficulty".$numRow."' value='".$choise."'>".$choise."&nbsp;&nbsp;&nbsp;";
                        }
                    }
                ?>
            </td>
        </tr> 
        <?php $numRow++;                }$numRow--; ?> 
    </table> 
    <input name="next" type="submit" value="continue" onclick="return true;">
    </form>

它工作得很好,每一行上的单选按钮的diffrent值都很好,但问题是,我该如何处理它?我在想,也许把所有选取的raio按钮值都发送到一个数组?

我也在同一个页面上得到了这一部分,因为在用户选择了所有内容后:

<?php 
    if(isset($_POST['next']) ) 
    { 
        if(isset($_POST['difficulty2']))
            $difficulty2 = $_POST['difficulty2'];
                    else
            $difficulty2="";
        if(isset($_POST['difficulty1']))
            $difficulty1 = $_POST['difficulty1'];
        else
            $difficulty1="";
        echo "User Has submitted the form and entered this difficulty1 : <b> $difficulty1 </b></br>";
        echo "User Has submitted the form and entered this difficulty2 : <b> $difficulty2 </b></br>";           
    }
    else
    {
?>

我可以得到这样的值,但有没有比只检查有多少行并循环添加数组中的所有POST更干净、更快的方法?我希望我能说清楚并感谢你的帮助:P

for($choise=1;  $choise<6;  $choise++)
{
    echo "<input type='radio' name='difficulty[".$numRow."]' value='".$choise."'>".$choise."&nbsp;&nbsp;&nbsp;";
}

然后

$difficulty = isset($_POST['difficulty'])?$_POST['difficulty']:'';
echo "User Has submitted the form and entered this difficulty1 : <b> {$difficulty[0]} </b></br>";
echo "User Has submitted the form and entered this difficulty2 : <b> {$difficulty[1]} </b></br>"; 

备注

action="<?php echo $_SERVER['PHP_SELF']?>"

这对xss 不好

尝试:

echo '<input type="radio" name="difficulty['.$numrow.']" value="'.$choise.'" />';

那么$_POST['difficulty']将是一个数组,该数组由具有所选选项值的行号索引。