我如何将SmartyStreets验证应用于同一页面中的两种表单?
```.col-md-6%h3美国地址
%form.form-horizontal%label街道地址%input.form-control {id:'street',name:'street',style:'margin-bottom:10px; font-size:13px; height:30px''}
%label City%input.form-control {id:'city',name:'city',style:'margin-bottom:10px; font-size:13px; height:30px''}
%label state State input.form-control {id:'state',name:'state',style:'margin-bottom:10px; font-size:13px; height:30px''}
%标签邮政编码%input.form-control {id:'zipcode',name:'zipcode',style:'margin-bottom:10px; font-size:13px; height:30px''}
.row%br%br%input.btn.btn-ss-alt.btn-lg {type:“submit”,name:“commit”,style:“margin-bottom:20px; float:right; margin-right: 15px; padding:10px 72px;“}
.col-md-6%h3国际地址
%form.form-horizontal%label街道地址%input.form-control {id:'street',name:'street',style:'margin-bottom:10px; font-size:13px; height:30px''}
%label City%input.form-control {id:'city',name:'city',style:'margin-bottom:10px; font-size:13px; height:30px''}
%label state State input.form-control {id:'state',name:'state',style:'margin-bottom:10px; font-size:13px; height:30px''}
%标签邮政编码%input.form-control {id:'zipcode',name:'zipcode',style:'margin-bottom:10px; font-size:13px; height:30px''}
.row%br%br%input.btn.btn-ss-alt.btn-lg {type:“submit”,name:“commit”,style:“margin-bottom:20px; float:right; margin-right: 15px; padding:10px 72px;“}```
SmartyStreets插件仅适用于第一种形式,不适用于第二种形式。
var liveaddress = $.LiveAddress({ key: #{ENV['SMARTY_STREETS']}, debug: true, addresses: [{ street: '#street', city: '#city', state: '#state', zipcode: '#zipcode' }] });
很简单,只需将每个表单封装在表单标签中,并为每个字段分配一个不同的名称(或ID)即可。 该插件会将其提取出来。 以下是使用自定义字段映射的两种形式的示例:
http://jsfiddle.net/p02qxh0L/69/
以下是使用自动映射在同一页面上的16个窗体的示例:
https://smartystreets.com/docs/plugin/examples
HTML示例:
<form id="shipping">
<input type="text" id="pais" name="pais" placeholder="pais">
<br>
<br>
<input type="text" id="calle" name="calle" placeholder="calle">
<br>
<input type="text" id="ciudad" name="ciudad" placeholder="ciudad">
<br>
<input type="text" id="estado" name="estado" placeholder="estado">
<br>
<input type="text" id="codigo" name="codigo" placeholder="codigo">
<br>
</form>
<hr>
<form id="billing">
<input type="text" id="pais2" name="pais2" placeholder="pais2">
<br>
<br>
<input type="text" id="calle2" name="calle2" placeholder="calle2">
<br>
<input type="text" id="ciudad2" name="ciudad2" placeholder="ciudad2">
<br>
<input type="text" id="estado2" name="estado2" placeholder="estado2">
<br>
<input type="text" id="codigo2" name="codigo2" placeholder="codigo2">
<br>
</form>
示例Javascript
evar ss = jQuery.LiveAddress({
key: '5640108848371823003',
waitForStreet: true,
debug: true,
addresses: [{
country: '#pais',
street: '#calle',
city: '#ciudad',
state: '#estado',
zipcode: '#codigo'
},{
country: '#pais2',
street: '#calle2',
city: '#ciudad2',
state: '#estado2',
zipcode: '#codigo2'
}]
});
链接地址: http://www.djcxy.com/p/46035.html
上一篇: How can I apply SmartyStreets validation to two forms in the same page?