简体   繁体   English

防止在表单提交时对加号进行编码

[英]Prevent plus sign from being encoded on form submit

So, I've got a search form on my site that is GET submitting to a third party site.所以,我的网站上有一个搜索表单,可以提交给第三方网站。 One of the input values is for subdivision names, and the third party requires that it be the subdivision name with + symbols for spaces.输入值之一是用于细分名称,第三方要求它是带有空格的+符号的细分名称。 So, my value is getting parsed and replacing the spaces with +'s, however, when submitting, the values get urlencoded by the browser and in turn don't get parsed by the 3rd party.. My first thought is that they're not doing their job by not decoding the values on their end... But before I begin the painful process of dealing with their customer support, I'd rather check here first and see if there's a way I can work around it.因此,我的值正在被解析并用 + 替换空格,但是,在提交时,这些值会被浏览器进行 urlencoded,而不会被第 3 方解析。我的第一个想法是它们是没有通过不解码他们的最终价值来完成他们的工作......但在我开始处理他们的客户支持的痛苦过程之前,我宁愿先在这里检查一下,看看是否有办法解决它。

EDIT: here's my code (urls have been removed)编辑:这是我的代码(网址已被删除)

<form action="IDXBroker" method="GET">
    <h2>IDX Quick Search</h2>
    <div class="element">
        <label for="pt">Property Type</label>
        <select name="pt" id="pt">
            <option value="all">All</option>
            <option value="1" selected="selected">Residential</option>
            <option value="2">Commercial</option>
            <option value="3">Lots and Land</option>
            <option value="4">Rental</option>
            <option value="5">Multi-Family</option>
        </select>
    </div>
    <div class="element" ng-controller="searchCtrl" class="city-search">
        <label for="city">City/Subdivision</label>
        <input type="text" ng-model="searchTerm" ng-change="setShowResults()"/>
        <ul class="city-results" ng-show="showResults && searchTerm.length >= 3">
            <li ng-repeat="item in results | stringSearch:searchTerm"><a href="#" ng-click="selectCity(item)">{{item.data}}</a></li>
            <li ng-show="(results | stringSearch:searchTerm).length === 0 && searchTerm.length >= 3">No Results Found</li>
        </ul>
        <input type="hidden" name="{{searchType}}" value="{{searchTermValue.split(' ').join('+')}}" />
    </div>
    <div class="element">
        <label for="lp">Min Price</label>
        <input id="lp" name="lp" type="number" value="200000" />
    </div>
    <div class="element">
        <label for="hp">Max Price</label>
        <input id="hp" name="hp" type="number" />
    </div>
    <div class="element">
        <label for="bd">Min Bedrooms</label>
        <input id="bd" name="bd" type="text" />
    </div>
    <div class="element">
        <label for="tb">Max Bedrooms</label>
        <input name="tb" type="text" />
    </div>
    <input type="hidden" name="srt" value="newest" />
    <div class="buttons">
        <input type="submit" value="Search Now" />
    </div>
</form>

Not sure you can force the browser to not encode the plus signs.不确定您是否可以强制浏览器不对加号进行编码。 As a workaround you could just reload the window with js.作为一种解决方法,您可以使用 js 重新加载窗口。 Something like就像是

var id1value = document.getElementById('hp').value;
var id2value = document.getElementById('lp').value;
//repeat for all your inputs to build your string

var q = 'hp=' + id1value + '&lp=' + id2value;

window.location = 'http://IDXBrokerURL?' + q;`

add an onclick to the submit to run your js function.向提交添加一个 onclick 以运行您的 js 函数。 Then there is no encoding at all.然后根本没有编码。

I'll get this encoding issue submitted to their developers support.我会将这个编码问题提交给他们的开发人员支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM