douke1905 2016-03-02 19:42
浏览 328
已采纳

一个表单中的多个“链接”提交按钮

I would like to create a form with multiple submit link buttons. I know it can be done by using and specifying the name of <button> or <input type="button"> something like this:

In HTML:

<form action="" method="get">
  Other form elements here...
  <button type="submit" name="activated">Activated</button>
  <button type="submit" name="pending">Pending</button>
  <button type="submit" name="suspended">Suspended</button>
</form>

In PHP:

<?php
if(isset($_GET["activated"])) {
  Activated codes here...
}
elseif(isset($_GET["pending"])) {
  Pending codes here...
}
elseif(isset($_GET["suspended"])) {
  Suspended codes here...
}
?>

I want the submit buttons to be done by using link, not <button> or <input type="submit"> something like this:

<a href="#">Activated</a>
<a href="#">Pending</a>
<a href="#">Suspended</a>

I heard that it can be done by using JavaScript or JQuery but I don't know how, anyone knows?

Update: What I want to happen is when I clicked the "Activated" link for example, I want only to process the logic under isset($_GET["activated"]).

The reason behind:

The reason why I want to have a submit link buttons instead of normal submit button tags is that, I want to use this bootstrap dropdown button style to change the status of user(s) on table:

and it is based on links, so that's why.

PS: Sorry for bad English, not my native language.

  • 写回答

3条回答 默认 最新

  • doulai2573 2016-03-02 20:31
    关注

    You could use data attributes on your anchors, then load that attribute into a hidden field to check in your PHP code.

    <form action="" method="post">
        <a href="#" class="anchor-btn" data-name="activated">Activated</a>
        <a href="#" class="anchor-btn" data-name="pending">Pending</a>
        <a href="#" class="anchor-btn" data-name="suspended">Suspended</a>
        <input type="hidden" id="actionName" name="actionName" value="" />
    </form>
    
    $('.anchor-btn').click(function(e) {
        e.preventDefault();
        $('#actionName').val($(this).data('name'));
        $('form').submit();
    });
    
    <?php
        if($_POST['actionName'] == "activated") {
            Activated code goes here
        }
        ...etc.
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景