动态将GET参数添加到表单提交的URL [英] Dynamically adding GET parameter to URL on form submit

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

问题描述

我在PHP应用程序中有一个简单的表单,必须通过POST方法提交.像这样:

I have a simple form in a PHP application that I have to submit via POST method. Something like:

<form action="URL?page_id=10" method="POST">
    <select name="some_name" id="some_id">
        <option value='1'>...</option>
        <option value='2'>...</option>
        ...
    </select>
    ...
    //submit button here
</form>

目标是在提交时转到以下URL:

The goal is to go to the following URL on submit:

URL?page_id=10&selected_id=SELECTED_ID

其中 SELECTED_ID 是用户从表单的选择下拉菜单中选择的值.通过将整个表单转换为以GET形式发布参数来完成此操作,因为我需要在URL中显示此 SELECTED_ID .但是,出现了另一个要求,说我需要通过POST传递所有内容,并且仍然在URL中显示 SELECTED_ID ,现在我正在寻找替代方法.

where SELECTED_ID is the value chosen by the user from the select drop down menu in the form. I've done it by converting the whole form to post the parameters as GET as I need to have this SELECTED_ID visible in the URL. However, another requirement turned up saying that I need to pass everything through POST and still have the SELECTED_ID visible in the URL and now I'm looking for alternatives.

所以问题归结为:如何在提交POST表单时使用与表单一起提交的值之一动态地向URL添加另一个GET参数?

So the question gets down to: how can I add dynamically another GET parameter to the URL upon POST form submission with one of the values submitted with the form?

推荐答案

首先,您必须在表单中添加一个ID,如下所示:

first you have to add a id to your form as below

< form id ='form1'action ="URL?page_id = 10" method ="POST">

然后在您的按钮上单击添加下面的呼叫功能

then add call below function on your button click

 function test(){
    $('#form1').attr('action', $(this).attr('formaction')+'&selected_id='+$('#some_id').val());
    }

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

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