dqenv99518 2011-08-07 13:36
浏览 16
已采纳

Php - 单击了哪个按钮

I am writing a script where I provide two buttons "Grant" and "Revoke" to the user. The problem is that both of them are set and "Grant" button always takes precedence.

Below is Sample code

<form name="form_access" id="form_access" action="" method="POST" class="access">
|
|
| 

<input type="hidden" name="accessaction" value="Grant Access"/>
<input type="hidden" name="revokeaction" value="Revoke Access"/>

<a id="_access_btt" class="button" href="#">Grant Access</a>

    <img class="ajaxload" style="display:none;" id="ajaxld" src="images/ajax-loader.gif"/>
    <a id="_revoke_btt" class="button" href="#">Revoke Access</a>

    <img class="ajaxload" style="display:none;" id="ajaxld1" src="images/ajax-loader.gif"/>
</form>
  • 写回答

2条回答 默认 最新

  • drzrdc1766788 2011-08-07 13:43
    关注

    Rather than using two hidden elements, Why dont you use a single hidden element, something like this?

    for example: you could use:

    <input type="hidden" name="accessPermission" value=""/>
    

    and depending upon what button user clicks, with the help of javascript you could set this action's value too:

    document.form_access.accessPermission.value = "Revoke Access"
    

    and

    document.form_access.accessPermission.value = "Grant Access"
    

    and then submit the form!

    so in the end, you can just check value $_REQUEST['accessPermission'] in your PHP,

    and you will get whatever value you have set for your hidden form element accessPermission:

    if its value is Revoke Access you will get $_REQUEST['accessPermission'] as 'Revoke Access'

    if its value is Grant Access you will get $_REQUEST['accessPermission'] as 'Grant Access'

    So at the end, you can construct your form as:

    <form name="form_access" id="form_access" action="" method="POST" class="access">
    |
    |
    | 
    
    <input type="hidden" name="accessPermission" value=""/>
    
    <a id="_access_btt" class="button" href="javascript:document.form_access.accessPermission.value = 'Grant Access'">Grant Access</a>
    
        <img class="ajaxload" style="display:none;" id="ajaxld" src="images/ajax-loader.gif"/>
        <a id="_revoke_btt" class="button" href="javascript:document.form_access.accessPermission.value = 'Revoke Access'">Revoke Access</a>
    
        <img class="ajaxload" style="display:none;" id="ajaxld1" src="images/ajax-loader.gif"/>
    </form>
    

    And Both the values are set because, its really specifically set by the lines:

    <input type="hidden" name="accessaction" value="Grant Access"/>
    <input type="hidden" name="revokeaction" value="Revoke Access"/>
    

    Grant Action takes precedence, because that's appears first.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类