我是否将 Javascript 用于 HTML
我目前正在制作贝宝结帐表格。该表单允许用户指定一些选项,当他们提交表单时,它会将订单提交给 PayPal 进行处理。
该表单有一个
<select name="srt"> <!-- User specifies amount of times payment should recur -->
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
</select>
<input type="hidden" name="src" value="1"> <!-- Specifies that payment should be recurring-->
这在大多数情况下都有效,但是当用户使用 srt
value="1"
选择第一个选项时,paypal 相反希望这是提交时 srt
为空或省略,src
(表单下方的隐藏输入)为 value="0"
。这样做的原因似乎是,如果付款重复 1 次,即仅向客户收取一次费用,那么这根本不是定期付款,因此 srt
无效,而是 < code>src(指定是否应重复付款)应设置为 0
。
我想知道处理这个问题的最佳方法是什么。我唯一能想到的是使用 javascript 根据用户在
这是处理这个问题的最佳方法,还是有更好的方法不需要浏览器处理 javascript?
谢谢!
I'm currently working on a paypal checkout form. The form allows the user to specify a few options and when they submit the form, it submits the order to paypal for processing.
The form has a <select>
droplist that allows a user to select how many times they want a subscription to recur. It is set up like this:
<select name="srt"> <!-- User specifies amount of times payment should recur -->
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
</select>
<input type="hidden" name="src" value="1"> <!-- Specifies that payment should be recurring-->
This works in most cases, however when the user selects the first option with the srt
value="1"
, paypal instead wants this to be submitted with srt
blank or omitted and src
(the hidden input below the form) with value="0"
. The reason for this seems to be that if the payment is to recur 1 time, meaning to charge the customer only once, then this is not a recurring payment at all, so srt
is not valid and instead src
, which specifies if payments should recur or not, should be set to 0
.
I'm wondering what is the best way to handle this. The only thing I can think of is to use javascript to set hidden form values depending on what the user selects in a <select>
drop list.
Is that the best way to handle this, or is there a better way that does not require the browser to handle javascript?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我想澄清的是,在浏览器中计算的所有值必须在服务器上进行验证。服务器端验证确实无可替代。客户端脚本只能用于改善用户体验。 如果不这样做,就会出现一个等待被利用的安全漏洞。
srt
将永远不会被发布。srt
禁用并隐藏。src
的初始值应为0
。srt
。src
的值设置为等于用户在srt
中选择的值。srt
和src
。DEMO
标记:
jQuery:
First of all I would like to make it clear that all values computed in the browser must be validated on the server. There really is no substitute for server side validation. Client-side scripts must only be used to improve user experience. Failing to do so is a security hole waiting to be exploited.
srt
will never get posted.srt
both disabled and hidden.src
should have a value of0
to start with.srt
via Javascript.src
equal to whatever the user selects insrt
.srt
andsrc
if the user ever unchecks the checkbox.DEMO
Markup:
jQuery: