【问题标题】:handling multiple buttons with same name and value in one form以一种形式处理具有相同名称和值的多个按钮
【发布时间】:2012-08-26 01:57:09
【问题描述】:

我在一个网站上有多个提交按钮。他们过去常常上下移动元素,我希望以一种完整的形式成为它们,以防用户更改同时一些其他值,以便保存所有内容。现在的问题是我需要被点击的按钮的元素 ID。

所以这是循环中的代码:

div class="form-order"><?php echo $elements[$z]['element_order']; ?> </div>
<input type="submit" name="edit_form_operation" value="&#9650;" class="button-primary" 
<?php if($elements[$z]['element_order'] == 1) echo 'disabled="disabled"'; ?> /><br />

<input type="submit" name="edit_form_operation" value="&#9660;" class="button-primary" 
<?php 
$highest_element = $fdb->get_element_highest_order($form[$i]['form_id']);
if($elements[$z]['element_order'] == $highest_element) echo 'disabled="disabled"'; ?> />

在 for 循环中单击特定按钮时,他应该先编写此代码,以便我知道必须移动哪个元素

echo '<input type="hidden" name="change_element_id" value="'.$elements[$z]['element_id'].'" >';

我也愿意为这个问题提供另一种解决方案。

【问题讨论】:

  • 如果需要被点击按钮的ID,可以使用mybutton.onclick=function(){this.id;}。但我不太明白你在做什么......
  • 我想你只是在问如何支持多个提交按钮,并知道点击了哪个按钮。见techrepublic.com/article/…
  • 是的,但我想保持按钮的值相同,以便它们具有相同的名称。

标签: javascript forms button


【解决方案1】:

好的,我现在就这样解决了

在这里你处理输入:

// Select Operation
    if(isset($_POST['edit_form_operation_up'])) {
        echo "move up id ";
        $operation = array_keys($_POST['edit_form_operation_up']);
        echo $operation['0'];
    }
    else if(isset($_POST['edit_form_operation_down'])) {
         echo "move down id ";
         $operation = array_keys($_POST['edit_form_operation_down']);
         echo $operation['0'];
    }

这是在无限元素的 for 循环中,输入具有相同的值和名称。

<?php $elements = $fdb->get_elements($form[$i]['form_id']); 
for($z = 0; $z < sizeof($elements); $z++) {
?>
<tr>
    <td><div class="form-order"><?php echo $elements[$z]['element_order']; ?> </div>
        <input type="submit" name="edit_form_operation_up[<?php echo $elements[$z]['element_id']; ?>]" value="&#9650;" class="button-primary" 
        <?php if($elements[$z]['element_order'] == 1) echo 'disabled="disabled"'; ?> /><br />
        <input type="submit" name="edit_form_operation_down[<?php echo $elements[$z]['element_id']; ?>]" value="&#9660;" class="button-primary" 
        <?php 
        $highest_element = $fdb->get_element_highest_order($form[$i]['form_id']);
        if($elements[$z]['element_order'] == $highest_element) echo 'disabled="disabled"'; ?> />
    </td>
    <td><?php echo $elements[$z]['element_id']; ?> </td>
    <td></td>
    <td></td>
</tr>
<?php } ?>

万一有人发现这个话题并想找到一个好的解决方案。

问候

【讨论】:

    猜你喜欢
    • 2021-03-15
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    相关资源
    最近更新 更多