HTML <input />元素不是POSTing值?

时间:2015-12-05 23:55:32

标签: php html cross-browser

好的,这很奇怪。

我能说的最好,我的代码是正确的。它适用于Mac上的Safari,iPhone上的Safari和Android平板电脑上的Google Chrome。然而,它的工作是Firefox或Internet Explorer;我无法为我的生活找出原因!

问题是:当我点击<input>标记并提交表单时,此标记的值未被POST。更奇怪的是,X和Y值发布 - 这是一个图像输入标签 - 但没有价值。

以下是HTML的相关内容:

<input type='image' name="edit" value="59" class="news-control news-control-hidden" src="assets/edit.png"/></input>

以下是点击代码时发布的值,作为print_r($_POST)调用的输出:

Array ( [edit_x] => 29 [edit_y] => 9 )

我的PHP网页上有以下代码:

<form name="newsform" method="post" action="Admin.php">
    <table class="editable-list">
<?php
        $entries = get_news_posts();
        if (empty($entries)) {
?>
            <tr><td><p style='margin: 6px 10px 16px 0px'>No news posts exist.<br><br>Click the button below to create one.</p></td></tr>
<?php
        } else
            foreach ($entries as $row) {
                make_editable_news_item($row['date'], $row['content'], $row['ID'], isset($_POST['edit']) ? $_POST['edit'] : null);
            }
        if (!isset($_POST['edit'])) {
?>
            <tr><td class='news-add-post' colspan='7'>
                <input type="submit" name="create_new" value="Create new post"/><br>
            </td></tr>
<?php                       }       ?>
    </table>
</form>

我也有这个功能:

    function make_editable_news_item($datestamp, $content, $id, $editing_id) {
?>
    <tr class="news-item">
        <td class="news-controls">
<?php   if ($id == $editing_id) {       ?>
                <input type='image' class="news-control" src="assets/undo.png"/></input>
<?php       } else if (!isset($editing_id)) {                   ?>
                <input type='image' name="edit" value="<?= $id ?>" class="news-control news-control-hidden" src="assets/edit.png"/></input>
<?php       }       ?>
            &nbsp;
        </td>
        <td class="news-datestamp">
            <?= format_datestamp($datestamp) ?>
<?php   if ($id == $editing_id) {       ?>
                <div style="background-color: #eee; height: 1px; margin: 6px;"></div>
                <div class="news-control-datestamp">
                    <input name='update_date' class="news-control-datestamp" type="checkbox">
                        Update
                    </input>
                </div>
<?php       }       ?>
        </td>
        <td class="news-separator"/>
        <td class="news-divider"/>
        <td class="news-separator"/>
        <td class="news-content">
<?php   if ($id == $editing_id) {       ?>
                <textarea name="content" class="news-content"><?= $content ?></textarea>
<?php   } else {    ?>
                <div class="news-content"><?= $content ?></div>
<?php       }       ?>
        </td>
        <td class="news-separator"/>
        <td class="news-separator"/>
        <td class="news-separator"/>
        <td class="news-controls">
<?php   if ($id == $editing_id) {       ?>
                <input type='image' name='save' value='<?= $id ?>' class="news-control" src="assets/save.png"/></input>
<?php       } else if (!isset($editing_id)) {                   ?>
                <input type='image' name="delete" value="<?= $id ?>" class="news-control news-control-hidden" src="assets/delete.png"/></input>
<?php       }       ?>
            &nbsp;
        </td>
    </tr>
    <tr class="news-separator"></tr>
<?php } ?>

此代码产生以下HTML:

<form name="newsform" method="post" action="Admin.php">
    <table class="editable-list">
    <tr class="news-item">
        <td class="news-controls">
            <input type='image' name="edit" value="59" class="news-control news-control-hidden" src="assets/edit.png"/></input>
            &nbsp;
        </td>
        <td class="news-datestamp">     5th Dec 2015<br>11:12pm         </td>
        <td class="news-separator"/>
        <td class="news-divider"/>
        <td class="news-separator"/>
        <td class="news-content">
            <div class="news-content">...</div>
        </td>
        <td class="news-separator"/>
        <td class="news-separator"/>
        <td class="news-separator"/>
        <td class="news-controls">
            <input type='image' name="delete" value="59" class="news-control news-control-hidden" src="assets/delete.png"/></input>
            &nbsp;
        </td>
    </tr>
    <tr class="news-separator"></tr>
        <tr><td class='news-add-post' colspan='7'>
            <input type="submit" name="create_new" value="Create new post"/><br>
        </td></tr>
    </table>
</form>

所以问题是,为什么Firefox和IE不尊重输入标签的value属性?

1 个答案:

答案 0 :(得分:2)

图像输入应该用于服务器端图像映射。

他们没有发布他们的价值观,他们发布(name.xname.y(PHP会将.转换为_,因为您不能.在一个变量名中,所以它会失败,使用旧的,默认的寄存器全局))你点击的像素的坐标。

如果要传递值,请改用常规提交按钮。

<button name="edit" value="59">
    <img src="assets/edit.png" alt="Edit: 59">
</button>