在表单提交

时间:2015-07-22 11:13:00

标签: javascript php jquery html forms

我在PHP应用程序中有一个简单的表单,我必须通过POST方法提交。类似的东西:

<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?page_id=10&selected_id=SELECTED_ID

其中SELECTED_ID是用户从表单中的选择下拉菜单中选择的值。我已经通过将整个表单转换为将参数发布为GET来完成它,因为我需要在URL中显示此SELECTED_ID。但是,另一项要求出现了,我需要通过POST传递所有内容,并且仍然可以在网址中看到SELECTED_ID,现在我正在寻找替代方案。

所以问题归结为:如何在POST表单提交时动态地将另一个GET参数添加到URL,其中一个值与表单一起提交?

2 个答案:

答案 0 :(得分:1)

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

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

然后在按钮上添加以下功能调用

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

答案 1 :(得分:0)

使用'data.frame': 1 obs. of 118 variables: $ totalCount : int 37544 $ count : int 5 $ sold.location.streetAddress : Factor w/ 1 level "Fleminggatan 107": 1 $ sold.location.position.latitude : num 59.3 $ sold.location.position.longitude : num 18 $ sold.location..Kungsholmen. : Factor w/ 1 level "Kungsholmen": 1 $ sold.location.region.municipalityName : Factor w/ 1 level "Stockholm": 1 $ sold.location.region.countyName : Factor w/ 1 level "Stockholms län": 1 $ sold.location.ocean : int 2507 $ sold.listPrice : int 3295000 $ sold.rent : int 1961 $ sold.floor : int 2 $ sold.livingArea : int 39 $ sold.source.name : Factor w/ 1 level "Edward & Partners Fastighetsmäklare AB": 1 $ sold.source.id : int 410 $ sold.source.type : Factor w/ 1 level "Broker": 1 $ sold.source.url : Factor w/ 1 level "http://www.edwardpartners.se/": 1 $ sold.rooms : int 2 $ sold.published : Factor w/ 1 level "2015-07-10 16:45:52": 1 $ sold.constructionYear : int 1909 $ sold.objectType : Factor w/ 1 level "Lägenhet": 1 $ sold.booliId : int 1918163 $ sold.soldDate : Factor w/ 1 level "2015-07-21": 1 $ sold.soldPrice : int 3920000 $ sold.url : Factor w/ 1 level "https://www.booli.se/bostad/lagenhet/kungsholmen/fleminggatan+107/1918163": 1 $ sold.location.streetAddress.1 : Factor w/ 1 level "Astrakangatan 110A": 1 $ sold.location.position.latitude.1 : num 59.4 $ sold.location.position.longitude.1 : num 17.8 $ sold.location..Hässelby. : Factor w/ 1 level "Hässelby": 1 $ sold.location.region.municipalityName.1: Factor w/ 1 level "Stockholm": 1 $ sold.location.region.countyName.1 : Factor w/ 1 level "Stockholms län": 1 $ sold.listPrice.1 : int 1900000 $ sold.rent.1 : int 4678 $ sold.floor.1 : int 1 $ sold.livingArea.1 : int 60 $ sold.source.name.1 : Factor w/ 1 level "HusmanHagberg": 1 $ sold.source.id.1 : int 1610 $ sold.source.type.1 : Factor w/ 1 level "Broker": 1 $ sold.source.url.1 : Factor w/ 1 level "http://www.husmanhagberg.se/": 1 $ sold.rooms.1 : int 2 $ sold.published.1 : Factor w/ 1 level "2015-07-17 22:10:35": 1 $ sold.constructionYear.1 : int 2006 $ sold.objectType.1 : Factor w/ 1 level "Lägenhet": 1 $ sold.booliId.1 : int 1920703 $ sold.soldDate.1 : Factor w/ 1 level "2015-07-21": 1 $ sold.soldPrice.1 : int 2000000 $ sold.url.1 : Factor w/ 1 level "https://www.booli.se/bostad/lagenhet/hasselby/astrakangatan+110a/1920703": 1 $ sold.location.streetAddress.2 : Factor w/ 1 level "Borensvägen 12": 1 $ sold.location.position.latitude.2 : num 59.3 $ sold.location.position.longitude.2 : num 18.1 $ sold.location..Årsta. : Factor w/ 1 level "Årsta": 1 $ sold.location.region.municipalityName.2: Factor w/ 1 level "Stockholm": 1 $ sold.location.region.countyName.2 : Factor w/ 1 level "Stockholms län": 1 $ sold.location.ocean.1 : int 3017 $ sold.listPrice.2 : int 2295000 $ sold.rent.2 : int 2988 $ sold.floor.2 : int 1 $ sold.livingArea.2 : int 52 $ sold.source.name.2 : Factor w/ 1 level "Fastighetsbyrån": 1 $ sold.source.id.2 : int 1573 $ sold.source.type.2 : Factor w/ 1 level "Broker": 1 $ sold.source.url.2 : Factor w/ 1 level "http://www.fastighetsbyran.se/": 1 $ sold.rooms.2 : int 2 $ sold.published.2 : Factor w/ 1 level "2015-07-04 01:08:46": 1 $ sold.constructionYear.2 : int 1945 $ sold.objectType.2 : Factor w/ 1 level "Lägenhet": 1 $ sold.booliId.2 : int 1915578 $ sold.soldDate.2 : Factor w/ 1 level "2015-07-21": 1 $ sold.soldPrice.2 : int 2550000 $ sold.url.2 : Factor w/ 1 level "https://www.booli.se/bostad/lagenhet/arsta/borensvagen+12/1915578": 1 $ sold.location.streetAddress.3 : Factor w/ 1 level "Helsingörsgatan 5": 1 $ sold.location.position.latitude.3 : num 59.4 $ sold.location.position.longitude.3 : num 17.9 $ sold.location..Kista. : Factor w/ 1 level "Kista": 1 $ sold.location.region.municipalityName.3: Factor w/ 1 level "Stockholm": 1 $ sold.location.region.countyName.3 : Factor w/ 1 level "Stockholms län": 1 $ sold.listPrice.3 : int 3295000 $ sold.rent.3 : int 5226 $ sold.floor.3 : int 5 $ sold.livingArea.3 : int 100 $ sold.source.name.3 : Factor w/ 1 level "HusmanHagberg": 1 $ sold.source.id.3 : int 1610 $ sold.source.type.3 : Factor w/ 1 level "Broker": 1 $ sold.source.url.3 : Factor w/ 1 level "http://www.husmanhagberg.se/": 1 $ sold.rooms.3 : int 5 $ sold.published.3 : Factor w/ 1 level "2015-06-23 21:56:06": 1 $ sold.constructionYear.3 : int 1978 $ sold.objectType.3 : Factor w/ 1 level "Lägenhet": 1 $ sold.booliId.3 : int 1911573 $ sold.soldDate.3 : Factor w/ 1 level "2015-07-21": 1 $ sold.soldPrice.3 : int 3330000 $ sold.url.3 : Factor w/ 1 level "https://www.booli.se/bostad/lagenhet/kista/helsingorsgatan+5/1911573": 1 $ sold.location.streetAddress.4 : Factor w/ 1 level "Ekholmsvägen 220": 1 $ sold.location.position.latitude.4 : num 59.3 $ sold.location.position.longitude.4 : num 17.9 $ sold.location..Skärholmen. : Factor w/ 1 level "Skärholmen": 1 $ sold.location.region.municipalityName.4: Factor w/ 1 level "Stockholm": 1 $ sold.location.region.countyName.4 : Factor w/ 1 level "Stockholms län": 1 $ sold.listPrice.4 : int 2600000 [list output truncated] ..所有字段值都会自动附加到网址