无法在PHP表单帖子中检索选定的单选按钮值


Cannot retrieve selected radio button value in PHP form post

我无法在表单帖子中获取所选单选按钮值。无论我选择哪个选项,我都会得到值"on"。请注意,这是在Wordpress插件选项页面中。

以下表格的代码:

?>
<div class="wrap">
    <?php screen_icon(); ?>
    <h2>Title</h2>
    <br />
    <form action="options-general.php?page=page" method="post">
    <table class="widefat">
    <thead>
        <tr>
            <th></th>
            <th>Site Name</th>
            <th>Site URL</th>
            <th>Username</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th></th>
            <th>Site Name</th>
            <th>Site URL</th>
            <th>Username</th>
        </tr>
    </tfoot>
    <tbody>
    <?php 
    $size = count($sites);
    for ( $i = 0; $i < $size; $i++) {
        echo '<tr>';
        for ($j = 0; $j < 4; $j++) {
            if ($j == 0) {

            echo '<td><input type="radio" id="cta_siteID_'.$i.'" name="cta_siteID",value="'.$i.'"/></td>';
            }
            else
            {
                echo '<td>'.$sites[$i][$j-1].'</td>';
            }
        }
        echo '</tr>';
    } 
    ?>
    </tbody>
   </table>
   <br />
   <input type="hidden" name="formType" value="main" />
   <select name="selectedItem">
        <option value="" selected="true">Select an Option</option>
        <option value="add">Add Site</option>
        <option value="edit">Edit Site</option>
        <option value="delete">Delete Site</option>
   </select>
   <input type="submit" name="Apply" value="Apply" class="button-primary" />
   </form>
</div>

当我在无线电组中选择一个项目后执行var_dump($_POST)时,我会得到以下内容:

onarray(4){["cta_siteID"]=>string(2)"on"["formType"]=>string(4)"main"["selectedItem"]=>字符串(4)"edit"["Apply"]=>string"5)"Apply"}

在发布表单之前,值在HTML中正确呈现,不确定发生了什么

无论我选择哪个单选选项,"on"值都会显示,如果没有选择,则根本不会显示(正如我所期望的)。

您的输入标记中不应该有逗号:

name="cta_siteID",value=

这很可能会导致浏览器中止正在传递的值。