[英]How can I merge 2 input values from a form before performing a form action?
我正在嘗試創建一個表單,以使用戶從他們輸入的位置獲取到預定義位置的指導。 我正在使用Bing Maps“創建自定義網址地圖”來實現此目的。
基於msdn( http://msdn.microsoft.com/zh-cn/library/dn217138.aspx ),我知道我需要表單來傳遞單個值,例如:rtp = adr.'addressfromuser'〜adr。 “預定義地址”。 我只是不知道如何合並表單值(或在用戶輸入前面插入adr。)。 我一直無法找到一種方法來執行此操作,因此我們將不勝感激。
我的表單代碼如下:
<form action="http://bing.com/maps/default.aspx" method="get" target="_blank">
<label for="rtp">From:</label>
<input class ="input" type="text" name="rtp" value="adr." /> <!--user input-->
<input type="hidden" name="rtp" value="~adr.Mission,TX" />
<!--predetermined destination-->
<input class="btn btn-primary" type="submit" type="submit" value="Get directions" />
</form>
Ding這樣得到的結果接近我想要的結果,但還不完全到那里(想要隱藏初始的“ adr。”,並且在傳遞第二個rtp之前不生成“ rtp =“。 注意:如果我注釋掉用戶輸入我成功地獲得了一個以最終目的地為b點的地圖,但沒有定義a點
如果我想做的是可能的幫助,不勝感激!
您需要將ftp輸入數組:
編輯:您需要刪除廣告adr.
在value="adr."
在兩個rtp
輸入上!
<form action="http://bing.com/maps/default.aspx" method="get" target="_blank">
<label for="rtp">From:</label>
<input class ="input" type="text" name="rtp[]" value="" /> <!--user input-->
<input type="hidden" name="rtp[]" value="Mission,TX" />
<!--predetermined destination-->
<input class="btn btn-primary" type="submit" value="Get directions" />
</form>
然后,當您處理表單時,您將像這樣對rtp[]
數組進行implode()
:
<?php
/* $_GET['rtp'] will look like this before implosion:
array(
0 => FromCity,UT
1 => ToCity,CA
)
*/
// You need to pre-append the adr. value to both strings by looping array
foreach($_GET['rtp'] as $value) {
$_rtp[] = "adr.'".$value."'";
}
/* Now $_rtp looks like this:
array(
0 => adr.'FromCity,UT'
1 => adr.'ToCity,UT'
)
*/
// Now implode this new array with "~"
// You could assign a new variable to the implode, but if you wanted to,
// you could override the same $_GET['rtp'] variable with it's imploded self.
$_GET['rtp'] = implode("~",$_rtp);
// Now the $_GET['ftp'] = adr.'FromCity,UT'~adr.'ToCity,UT'
?>
使用javascript / jquery
$('form').submit(function(){
//do your actions here
$('input[name=rtp]').value()
return false; // prevents submit by default action.
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.