动态将GET参数添加到表单提交的URL

编程入门 行业动态 更新时间:2024-10-26 19:35:38
本文介绍了动态将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

本文发布于:2023-10-10 22:50:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479979.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   参数   动态   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!