dongzhong8691 2014-09-11 14:45
浏览 25

如何在GET查询中不发送空输入值

I have a form like this

<form action="index.php" method="get">
  <input type="hidden" name="id" value="1">
  <input type="hidden" name="order_by" value="">
  <button type="submit">Submit</button>
</form>

It has some jQuery handlers to fill in "order_by" field. If I submit this form with empty "order_by" filed, I get an address like this: index.php?id=1&order_by=

What is the best way I can do to get following address after form submission if the "order_by" is empty: index.php?id=1 ?

  • 写回答

3条回答 默认 最新

  • dqlk31541 2014-09-11 14:49
    关注

    in php you can do like this

    if(!isset($_GET['order_by']) || !$_GET['order_by'])
        return 'error msg';
    

    or

    if(empty($_GET['order_by']))
        return 'error msg';
    

    change html like this

       <form action="index.php" method="get" onsubmit="return valid()">
      <input type="hidden" name="id" value="1">
      <input type="hidden" name="order_by" id="order_by" value="">
      <button type="submit">Submit</button>
      </form>
    

    javascript:

      function valid(){
       if(!$('#order_by').val()){
           alert("Order by not found");
           return false;
        }
       return true;
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证