douxi1968 2013-09-14 22:14
浏览 9
已采纳

未从表格[重复]发送的硬编码GET值

This question already has an answer here:

In the action attribute of my form element I have specified some get values, which will be sent along with the value from the actual form. However the values I have hardcoded in are not sent to the new document, what am I doing wrong?

 <form action="loginForm.php?type=dept" method="get">
    <select name="dept" onchange="this.form.submit()">
      <option value="">Department</option>
      <option value="Bar">Bar</option>
      <option value="Cleaning">Cleaning</option>
      <option value="Kitchen">Kitchen</option>
      <option value="Management">Management</option>
      <option value="Maintenance">Maintenance</option>
      <option value="Waiting">Waiting</option>
    </select>
  </form>

At the top of the loginForm file is this code, which will output 'Type not set' every time

if(!isset($_GET['type']))
{
    echo 'Type not set';
}
</div>
  • 写回答

2条回答 默认 最新

  • dqg2269 2013-09-14 22:18
    关注

    This is because the get parameters you are "forcing" by putting them in the URL are "overwritten" when the page is submitted. You will need to use a hidden field like:

    input type="hidden" name="type" value="valuehere" />
    

    Adding this to your form will submit this additional value.

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

报告相同问题?

悬赏问题

  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline