How to make paypal button fields 'Required'? - 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 this
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)

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.

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).

Related

Unable to test sandbox accounts on paypal

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="6DHWKYCKBGXFS">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
I have been trying it for weeks but no luck. what i have done so far is created two accounts on developer site then with business account i created donate button whose code is above.I pasted it on plain html page and it directed me to
https://www.paypal.com/us/cgi-bin/webscr?cmd=_flow&SESSION=bnXFinACSxCb1ODnXhGUvOIt9PAh_P89ZBULZpUJW...
where i entered my buyer account but i dont know why its keep sayiing "Please check your emai and password" . i have checked it hundred of times but i dont know why its not accepting this.Please help me , I am in big trouble.
Finaly after trying for weeks I found the solutuion.The four point in this https://developer.paypal.com/docs/classic/paypal-payments-standard/ht_test-pps-buttons/ tutorial is wrong. You dont create a button like that for testing purpose but rather go to profile>selling tools>create new button . Probably it will be helpful for someone..
If you are trying to tested this with your test buyer accounts, your seller accounts also needs to be set up in the sandbox. The above code is pointing to the live site "www.paypal.com", if you are trying to use your test seller and buyer accounts, the URL needs to be "www.sandbox.paypal.com"

paypal amount 0 on order summery page

Amount $0 on order summery page.
My Code for Buy Now Button is
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="AF">
<input type="hidden" name="amount" value="10.10">
<table>
<tr><td><input type="hidden" name="on0" value="License Option">License Option</td></tr><tr><td><select name="os0">
<option value="Single User">Single User </option>
<option value="Site License">Site License </option>
<option value="Global License">Global License </option>
</select> </td></tr>
</table>
<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_buynowCC_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_GB/i/scr/pixel.gif" width="1" height="1">
</form>
It looks like you have modified the button, which is what's probably causing the issue. When using a hosted button, typically the amount doesn't appear in the code. This is one of the reasons behind the hosted button, it keeps a person from viewing the code and modifying the amount. If you added the line of code in there for the amount, after creating your button this is probably the issue. Either you need to set the amount when creating the button in your account if you are wanting to use a hosted button. Otherwise if you want to be able to edit the amount in the code, you need to create a non hosted, clear text button. This can be done by setting your button not to be hosted on step 2 of the button creation process. Then once the code is generated, it will be encrypted. You have to then select clear text/un-encrypted to generate the HTML code that you can edit.
If you are trying to create button in your PayPal account, please do not change the name and value fields generated there. All data are saved in PayPal system and could not be modified in code line. If you are trying to create a customized button, please refer to below page for its details.
https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/buynow_buttons/#id08A2G0920QN
https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/

Paypal Custom Link

Regarding paypal buttons, I see plenty of stuff online that talks about creating a custom button to use in place in lieu of their official buttons.
What if I skipped using a button entirely and just used its alt tag to say what the link is?
<form target="_blank" action="https://www.paypal.com/cgi­bin/webscr" method="post">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="item_name" value="Blah blah blah">
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="no_note" value="1" />
<input class="alty" type="image" src="" border="0" name="submit" alt="Donation to specific project">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Just realized this doesn't work in Chrome, but it does work in FF. I'm just asking, say it did work in all browsers, would this be allowed, ie, just using alt tags to make it clear that it's a link to paypal's page?
Are there are workarounds that allows you to use a word/sentence that's a link to paypal's page, short of using paypal's email link?
In case anyone asks why I'm not using paypal's email link - it's because I cannot change the email address for that that link, whereas if I use code as in above, I can change the email address so the notification can go the the right person. (there are multiple programs in one department).
Advice?
Yes you can do it in this way also . You are allowed to use your link or images to direct to the PayPal checkout page .
And as far as the above code is concerned its working fine in chrome too , just tested it out .

Amount is not displaying in paypal form

I am using the following paypal code but still the amount is not displayed in paypal form once the website redirect the page to paypal.
`<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXXX">
<input type="hidden" name="amount_1" value="200">
<input type="image" style="width: 70px !important; padding: 0px !important;" src="http://www.merlioncricket.com/Login/static/images/payment.png" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>`
Please let me know, why the amount is not displaying.
Thanks,
Gladiator
Finally I found the answer, & maybe it is useful to others, whenever you create the paypal button make sure in step 2 "Save Button At PayPal" is not clicked & second once you create the button, remove code protection & then select the code & copy the paypal generated code.
It will solve the problem.
Thanks....
When using a hosted button, you can not pass over an amount. The hosted buttons, prevents someone from directly modifying the code and passing over a different amount. If you are wanting a different amount, you would need to log into your account and edit the hosted button. If you want to dynamically populate the amount, then you would need to create a non hosted clear text button.

What is a quick and dirty way to implement a PayPal discount code for buttons stored at PayPal?

I want to implement a solution that isn't too involved without the use of shopping carts.
I have detailed a solution in my own answer to this question, but would love if anyone could suggest a better way.
Thanks
I actually recently had to do this. My solution was "dirty" and "quick" without a doubt.
Basically, I created 2 separate HTML pages that were almost identical except for one had price options that were discounted and a message that said "Successful discount code!"
Then, you create a front page to those 2 purchase pages. This page asks them to enter a discount code. Example code below:
<form action="check-their-discount-code.php" method="POST" enctype="multipart/form-data">
Enter discount code below: <input type="text" name="Discount-code" >
<input type="submit" value="Submit">
</form>
Then a VERY simple PHP script:
<?php
// Collect Information from form
$discount_code = $_POST['Discount-code'];
// See if the Discount Code is correct
if($discount_code === "DISCOUNT_CODE") {
// Code is correct, redirect to discount page!! Yay!
header("Location: ../page-with-discounted-prices.html");
} else {
// Code is incorrect, redirect them to non-discounted page
header("Location: ../page-with-regular-prices.html");
}
?>
That is the quickest, dirtiest way to do it in my opinion! It worked just fine.
NOTE With this method the pages are not actually protected in any way, so if your customer discovers the Discounted Page's URL then they can easily buy the item at a discount. However, in my case, this did not happen. Also, users cannot look into PHP files so you are safe from anyone discovering your discount code.
Have a form with the following:
<tr><td><input type="hidden" name="dcode" value="Discount Code">Discount Code</td></tr><tr><td>
<input type="text" name="dcode2" maxlength="200"></td></tr>
And form action redirecting to a PHP form.
<form name =form action="register2.php" class="emailform" method="post" style ="" onsubmit="return verify()" >
In my code verify() is a JS function that returns if the form is valid or not, but the most basic code that you need is simply
<form name =form action="yourphp.php" method="post">
Then in your PHP form do the following. Paste the button code from PayPal
It should be something like this:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin-left:30px;">
<input type="hidden" name="discount_" value="medium">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="some value">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_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>
Not create as many PayPal buttons as needed, with whatever parameters. You have 2 options - set the price of the buttons as required - OR set the extra variables :
discount_amount, discount_amount2, discount_rate, discount_rate2 and discount_num as required in the box on PayPal that asks you to enter extra variables.
Now instead of the line
<input type="hidden" name="hosted_button_id" value="some value">
Have the following PHP
<?php
$dcode=$_POST["dcode2"];
if ($dcode === "discount code 1") {
echo "<input type=\"hidden\" name=\"hosted_button_id\" value=\"hosted button value 1\">\n";
}
else if ($dcode === "discount code 2") {
echo "<input type=\"hidden\" name=\"hosted_button_id\" value=\"hosted button value 2\">\n";
}
else {
echo "<input type=\"hidden\" name=\"hosted_button_id\" value=\"hosted button value 3\">\n";
}
?>
Now this is probably, no - definitely a terrible way to do it, but one that I could hack up in a few minutes; especially because PayPal lets me create similar buttons easily.
How would you do it.
Let me know.
Thanks