如何在提交时更改表单url参数? [英] How to change form url parameter on submit?

查看:204
本文介绍了如何在提交时更改表单url参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个表格供处理..

I have this form for processing..

<form action="driver.php" method="GET">
<input type="text" placeholder="Search" id="search" name="n">
<button type="submit">Submit</button>
</form>



默认情况下,网址为 http:/ /sites.com/driver.php?n=typedname

所以我在.htaccess中进行了修改并将其转换为 http://sites.com/driver/typedname 用于SEO友好网址 modrewrite问题 - 404错误感谢anubhava

so i did modifications in .htaccess and convert it to http://sites.com/driver/typedname for SEO friendly urls modrewrite issue - 404 error thanks to anubhava

一切都很顺利,但问题现在出现在我输入并点击提交按钮时,它会转到 http://sites.com/driver.php?n=typedname

everything is well, but the problem now comes when I type and click the submit button, it will go to http://sites.com/driver.php?n=typedname

所以我怎么能让它去点击提交后,网址 http://sites.com/driver/typedname

so how can I make it to go this url http://sites.com/driver/typedname instead after clicking submit?

我认为javascript可以做这个,所以我标记了它,希望我没错。

I think javascript can do this, so i tagged it, hope im not wrong.

谢谢。

推荐答案

jQuery



jQuery

$('button[type=submit]').click(function(e){
    e.preventDefault();
    e.stopPropagation();

    window.location = "http://sites.com/driver/" + $('#search').val();

    return false;
});

$('form').submit(function(e) { // you really need to class/ID your form
    // all that code
});

现在这很简单,很容易让你知道。您当然希望清理您的输入(在前端和后端都可以做到这一点。)

Now this is quick and dirty to give you the idea. You'd of course want to sanitize your input (good idea to do that on the front-end as well as the back-end).

这篇关于如何在提交时更改表单url参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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