合并 url 中的 2 个输入值 [英] merge 2 input values in url

查看:29
本文介绍了合并 url 中的 2 个输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的表格:

颜色:<input type="text" name="color"><br>汽车:<input type="text" name="car"><br><输入类型=提交"></表单>

当我输入颜色red"和汽车bmw"时,我得到这样的网址

http://mywebsite/?color=red&car=bmw >

我怎样才能在提交时让汽车数组变成颜色,这样它会像这样

http://mywebsite/?color=red+bmw

解决方案

我真的不知道有什么方法可以修改 HTML 表单以从两个单独的输入生成查询字符串.但是在处理表单提交的 PHP 脚本中,你试图获取的 URL 基本上是这样的:

$_GET['color'] = implode(' ', $_GET);未设置($_GET['汽车']);

这会将 $_GET 更改为

数组(大小=1)'颜色' =>字符串红色宝马"(长度=7)

就好像你已经提交

http://mywebsite/?color=red+bmw

I have form like this:

<form action="" method="get">
Color: <input type="text" name="color"><br>
Car: <input type="text" name="car"><br>
<input type="submit">
</form>

When i type color "red" and car "bmw" i get url like this

http://mywebsite/?color=red&car=bmw

how can i get car array into color on submit so that it would be like this

http://mywebsite/?color=red+bmw

解决方案

I don't really know of a way to modify the HTML form to produce that query string from two separate inputs. But in the PHP script that handles the form submission, the URL you're trying to get is basically the equivalent of this:

$_GET['color'] = implode(' ', $_GET);
unset($_GET['car']);

This will change $_GET to

array (size=1)
  'color' => string 'red bmw' (length=7)

as if you had submitted to

http://mywebsite/?color=red+bmw

这篇关于合并 url 中的 2 个输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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