如何将贝宝按钮字段设置为“必填”?

发布于 2024-12-16 20:43:40 字数 4801 浏览 3 评论 0原文

我使用 paypal 按钮生成器创建了一个立即付款按钮。

该按钮有 2 个字段,然后您按立即付款。

但是,如果您将这些字段留空,您仍然可以付款。

我想让这些字段成为“必填”,如果用户没有填写这些字段,他应该无法付款。如何?

该按钮未托管在 paypal 上,但按钮保护已开启。我希望按钮被加密。

编辑

我尝试了 javascript 表单验证,但没有成功,有帮助吗?

这是脚本

<form
action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<table>
<tr><td><input type="hidden" name="on0" value="first form">form 1</td></tr><tr><td><input type="text" name="os0" maxlength="200"></td></tr>
<tr><td><input type="hidden" name="on1" value="2nd form">2nd form</td></tr><tr><td><input type="text" name="os1" maxlength="200"></td></tr>
</table>
<input type="hidden" name="encrypted" value=" encryption here ">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

对使这些字段成为必需的有帮助吗?我会给你 3 票,因为我有 3 个 stackoverflow 帐户和一个接受的答案 - 这是我至少能做的:)

PS

我无法使表单验证工作,所以我试图隐藏除非填写表格,否则提交按钮到目前为止都不起作用。

更新 - @Last Rose Studios

我尝试了很多验证方法,最后我使用了我朋友的联系表单验证哈哈

validation.js

function has_id(id){try{var tmp=document.getElementById(id).value;}catch(e){return false;}
return true;}
function has_name(nm){try{var tmp=cfrm.nm.type;}catch(e){return false;}
return true;}
function $$(id){if(!has_id(id)&&!has_name(id)){alert("Field "+id+" does not exist!\n Form validation configuration error.");return false;}
if(has_id(id)){return document.getElementById(id).value;}else{return;}}
function $val(id){return document.getElementById(id);}
function trim(id){$val(id).value=$val(id).value.replace(/^\s+/,'').replace(/\s+$/,'');}
var required={field:[],add:function(name,type,mess){this.field[this.field.length]=[name,type,mess];},out:function(){return this.field;},clear:function(){this.field=[];}};var validate={check:function(cform){var error_message='Please fix the following errors:\n\n';var mess_part='';var to_focus='';var tmp=true;for(var i=0;i<required.field.length;i++){if(this.checkit(required.field[i][0],required.field[i][1],cform)){}else{error_message=error_message+required.field[i][2]+' must be supplied\n';if(has_id(required.field[i][0])&&to_focus.length===0){to_focus=required.field[i][0];}
tmp=false;}}
if(!tmp){alert(error_message);}
if(to_focus.length>0){document.getElementById(to_focus).focus();}
return tmp;},checkit:function(cvalue,ctype,cform){if(ctype=="NOT_EMPTY"){if(this.trim($$(cvalue)).length<1){return false;}else{return true;}}else if(ctype=="EMAIL"){exp=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;if($$(cvalue).match(exp)==null){return false;}else{return true;}}},trim:function(s){if(s.length>0){return s.replace(/^\s+/,'').replace(/\s+$/,'');}else{return s;}}};

paypal.html

<script src="validation.js"></script>


    <script>
    required.add('os0','NOT_EMPTY','1st form');

    required.add('os1','NOT_EMPTY','2nd form')

    </script>


<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="return validate.check(this)">
<input type="hidden" name="cmd" value="_s-xclick">
<table>
<tr><td><input type="hidden" name="on0" value="1st form">1st form<span class="required_star"> * </span></td></tr><tr><td><input type="text" name="os0" maxlength="200" id="os0" class="required"></td></tr>
<tr><td><input type="hidden" name="on1" value="2nd form">2nd form<span class="required_star"> * </span></td></tr><tr><td><input type="text" id="os1" name="os1" maxlength="200" class="required"></td></tr>
</table>
<input type="hidden" name="encrypted" value=" encryption here
">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

我有使用了 JavaScript,然后我读了你的答案,但我不会改变,因为它现在可以工作了,

我还有 2 个小问题

1-是否可以从 paypal 页面删除描述框,请参阅此在此处输入图像描述

2- 付款完成后,paypal 不会重定向到感谢页面,我创建了很多按钮,这只是不重定向(我没有取消页面)

i have created a pay now button using paypal button generator.

The button has 2 fields, and then you press pay now.

However, if you leave these fields empty, you can still pay

I want to make these fields "required", if a user didn't fill these fields, he should not be able to pay. How?

The button is not hosted on paypal, but the button protection is ON. I want the button to be encrypted.

EDIT

i tried javascript form validation, didn't work, any help?

here's the script

<form
action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<table>
<tr><td><input type="hidden" name="on0" value="first form">form 1</td></tr><tr><td><input type="text" name="os0" maxlength="200"></td></tr>
<tr><td><input type="hidden" name="on1" value="2nd form">2nd form</td></tr><tr><td><input type="text" name="os1" maxlength="200"></td></tr>
</table>
<input type="hidden" name="encrypted" value=" encryption here ">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

any help making these field required? I'll give you 3 up votes because i have 3 stackoverflow accounts and an accepted answer - that's the least i can do :)

PS

i couldn't make the form validation work, so i tried to hide the submit button unless the forms are filled, so far, that didn't work as well.

UPDATE - @Last Rose Studios

I tried many validation ways, finally i used my friend's contact form validation lol

validation.js

function has_id(id){try{var tmp=document.getElementById(id).value;}catch(e){return false;}
return true;}
function has_name(nm){try{var tmp=cfrm.nm.type;}catch(e){return false;}
return true;}
function $(id){if(!has_id(id)&&!has_name(id)){alert("Field "+id+" does not exist!\n Form validation configuration error.");return false;}
if(has_id(id)){return document.getElementById(id).value;}else{return;}}
function $val(id){return document.getElementById(id);}
function trim(id){$val(id).value=$val(id).value.replace(/^\s+/,'').replace(/\s+$/,'');}
var required={field:[],add:function(name,type,mess){this.field[this.field.length]=[name,type,mess];},out:function(){return this.field;},clear:function(){this.field=[];}};var validate={check:function(cform){var error_message='Please fix the following errors:\n\n';var mess_part='';var to_focus='';var tmp=true;for(var i=0;i<required.field.length;i++){if(this.checkit(required.field[i][0],required.field[i][1],cform)){}else{error_message=error_message+required.field[i][2]+' must be supplied\n';if(has_id(required.field[i][0])&&to_focus.length===0){to_focus=required.field[i][0];}
tmp=false;}}
if(!tmp){alert(error_message);}
if(to_focus.length>0){document.getElementById(to_focus).focus();}
return tmp;},checkit:function(cvalue,ctype,cform){if(ctype=="NOT_EMPTY"){if(this.trim($(cvalue)).length<1){return false;}else{return true;}}else if(ctype=="EMAIL"){exp=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;if($(cvalue).match(exp)==null){return false;}else{return true;}}},trim:function(s){if(s.length>0){return s.replace(/^\s+/,'').replace(/\s+$/,'');}else{return s;}}};

paypal.html

<script src="validation.js"></script>


    <script>
    required.add('os0','NOT_EMPTY','1st form');

    required.add('os1','NOT_EMPTY','2nd form')

    </script>


<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="return validate.check(this)">
<input type="hidden" name="cmd" value="_s-xclick">
<table>
<tr><td><input type="hidden" name="on0" value="1st form">1st form<span class="required_star"> * </span></td></tr><tr><td><input type="text" name="os0" maxlength="200" id="os0" class="required"></td></tr>
<tr><td><input type="hidden" name="on1" value="2nd form">2nd form<span class="required_star"> * </span></td></tr><tr><td><input type="text" id="os1" name="os1" maxlength="200" class="required"></td></tr>
</table>
<input type="hidden" name="encrypted" value=" encryption here
">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

I have used JavaScript, and then i read your answer, but i'm not gonna change because it works now

i still have 2 small questions

1- is it possible to remove the description box from paypal page see thisenter image description here

2- paypal is not redirecting to the thank you page after the payment is done, i created many button, it's just not redirecting (i don't have a cancel page)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森林很绿却致人迷途 2024-12-23 20:43:40

您可以使用 html5 输入属性“required”,这可以处理某些浏览器,而对于其他浏览器,您必须使用 javascript 来验证表单。

如果您不介意给您一个简单的例子,我将使用 jQuery。

$('form').submit(function(e){
    flag = false;
    $('[name="os0"], [name="os1"]').css('background','').each(function(){
        el=$(this);
        if(el.val().length == 0){
           flag = true;
           el.css('background','red');
        }
    });
    if(flag){
     return false;
    }
});

除非两个字段均已填写,否则将无法提交表单。我还通过将输入的背景变成红色(可选)来为用户添加一些反馈。

当然,这仅适用于现代浏览器或启用了 JavaScript 的旧版浏览器,仍然有一小部分会通过。在这种情况下,罗伯特建议您发布到服务器上的中间页面可能是个好主意。

you could use the html5 input attribute 'required', and that would take care of some browsers, for the others you would have to use javascript to validate the form.

I'll use jQuery if you don't mind to give you a quick example.

$('form').submit(function(e){
    flag = false;
    $('[name="os0"], [name="os1"]').css('background','').each(function(){
        el=$(this);
        if(el.val().length == 0){
           flag = true;
           el.css('background','red');
        }
    });
    if(flag){
     return false;
    }
});

this will prevent the form from being submitted unless both fields are filled out. I also added some feedback for the user by turning the background of the input red (optional).

Of course this will only work in modern browsers or older browsers with javascript enabled, there will still be a small percentage where it will pass through. In this case Robert's suggestion that you post to an in between page on your server might be a good idea.

追星践月 2024-12-23 20:43:40

在不修改按钮代码的情况下,您需要一个客户端解决方案(如您提到的),因为 POST 将直接发送到 PayPal (https://www.paypal.com/cgi-bin/webscr)。
或者,您可以将 POST 提交到服务器上的中间页面,并从那里的 PayPal 转发,以便也包含服务器端检查(仅当这些字段是绝对必需的,例如 JavaScript 被禁用的情况下) )。

Without modifying the button code, you'd need a client-side solution (like you mentioned), since the POST will go directly to PayPal (https://www.paypal.com/cgi-bin/webscr).
Alternatively, you could submit the POST to an inbetween page on your server, and forward from PayPal there on, in order to include a server-side check as well (only if the fields are absolutely required, in case JavaScript is disabled, for example).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文