将 URL 参数添加到表单 PHP HTML [英] adding URL parameters to a form PHP HTML

查看:32
本文介绍了将 URL 参数添加到表单 PHP HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 url get 参数放在表单操作中是否可以或正确?

Is it okay or correct to put a url get parameter in a form action?

<form method='get' action='index.php?do=search'>
  <input name='_search' type='text' value='What are you looking for?'>
  <button type='submit'> Search </button>
</form>

当我提交表单时,URL 更改为:

When I submit the form the URL is changed to:

index.php?_search=What are you looking for? (I've stripped %20)

我更喜欢阅读网址

index.php?do=search&_search=What are you looking for?

最好在表单中添加一个隐藏字段

Would it be best to add a hidden field into the form

<input type='hidden' name='do' value='search' />

推荐答案

在我看来,您应该将它们添加为隐藏字段.如果您可以通过隐藏表单字段来传递参数,那么尝试传递参数是没有意义的

In my opinion you should add them as hidden fields. There is no point to try to pass params if you can do it via hidden form field

使用:

<input type='hidden' name='do' value='search' />

这篇关于将 URL 参数添加到表单 PHP HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆