zoukankan      html  css  js  c++  java
  • php form表单提交时,action url中参数无效的解决方法

    表单提交时get方式的一个错误

    <form class="form-inline pull-right" method="get" action="<?=Url::to(['list', 'id' => $id, 'parentId' => $parentId]);?>">
    <input type="text" name="object" class="form-control input-sm" placeholder="输入Object前缀名匹配" value="<?=$_GET['object'];?>">
    <button type="submit" class="btn btn-primary btn-sm">查询</button>
    </form>

    表单提交时URL里有需要用到的参数但是得不到的时候想显士的没有显示出来,那么就需要解决
    一直获取不到表单action中的method参数值id=1&parentId=1
    后经查询发现,浏览器会将表单数据封装为字符串,如id=1&parentId=1,然后直接附在表单的 action URL 之后。
    这两者之间用问号(?)进行分隔。
    如果GET请求的表单action属性中已经包含参数,浏览器会直接将其过滤掉,再附加form表单数据

    因此,GET请求方式的表单的action属性中不能附带任何参数,如果需要附加额外的参数,可以采用如下方式:

    1. 采用POST请求方式,在form中增加属性method="post"即可。
    2. 如果仍然想使用GET请求方式,可以在form表单中添加相应的隐藏文本域,例如
    <form class="form-inline pull-right" method="get" action="<?=Url::to(['list', 'id' => $id, 'parentId' => $parentId]);?>">
    <input type="hidden" name="parentId" value="<?=$parentId;?>">
    <input type="hidden" name="id" value="<?=$id;?>">
    <input type="text" name="object" class="form-control input-sm" placeholder="输入Object前缀名匹配" value="<?=$_GET['object'];?>">
    <button type="submit" class="btn btn-primary btn-sm">查询</button>
    </form>



    原文地址:http://www.365mini.com/page/get-method-form-conflict-with-action-which-has-parameter.htm
  • 相关阅读:
    五)使用 easyui-tabs 遭遇错误 Unexpected Exception caught setting '_' on
    六)iframe 及父子页面之间获取元素、方法调用
    七)如何实现权限控制
    二)手动添加基础数据
    三)EasyUI layout
    四)绘树
    一)6张表
    RollingFileAppender
    GitLabCI VS Jenkins 对比
    Nacos 学习记录
  • 原文地址:https://www.cnblogs.com/l-zl/p/7094477.html
Copyright © 2011-2022 走看看