Creating a PayPal Payment Form
In HTML / CSS Techniques by Collis Ta'eedHow it Works
PayPal makes doing this very easy by providing those "Buy Now" buttons you've probably seen around the place. Basically when you see one of those buttons, it is really the submit button on an HTML form with all the form fields set to hidden. This is fine for when you have a set price and set item, but what if you want the user to specify how much they are paying, and what they are paying for.
For example if you are adding a payment form to your freelancing site then you would want the client to type in their invoice number and the amount they wish to pay. This is easily done by changing the <input> fields from hidden to text and stripping away the defaults so that the user can fill them in. So let's get started.
Step 1

Step 2

Next we log into our PayPal account and click the Merchant Services tab. Down the bottom right you'll see a link that says Buy Now Buttons, follow that through and you get to a form to create one of these buttons.
Complete the form, under item ID just type the number 1, and use similar dummy numbers for the Item Name and Price. We'll change those in the code later. Make sure you do NOT encrypt the button. The rest of the fields (weight etc) can be left blank.
Step 3
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="accounts@freelanceswitch.com">
<input type="hidden" name="item_name" value="Donation">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="9.00">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="AU">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">
</form>
Here's the code that PayPal gives me. As you can see the button is in fact a <form&rt; element that uses an image submit button. Most importantly we can change any of those hidden. input fields to actual text fields simply by changing the word hidden to text.
- Item Number The value you place in this field appears when the user goes to PayPal and clicks the down arrow for more details on their purchase (you can see it by entering some information in the test form below).
- Business This field is for the PayPal account being paid to. Make sure it's set to your account. The one I'm using is for accounts [@] freelanceswitch.com (which is linked to our sister site FreelanceSwitch).
- Currency Code
This is pretty straightforward. When creating the Buy Now button you can select different options for this setting. If for some reason you wanted to, you could also change this to a
<select>element and let your user choose what currency to pay in. - Item Name The item_name field is the one where your user describes what they are paying for. In the example form below I've used a select box to let the user choose what they are donating towards. You could just as easily change it to a text field and let the user type something in.
- Amount The only thing to note here, is that if the user types anything other than a number in here PayPal will return an error, so you might want to use some Javascript to do validation on this field and ensure it's a number - though that would be a whole other tutorial. So instead for my example form I've just written a $ sign before the text field, hoping that will make it a little more self explanatory.
Step 4
You might have noticed that there is no space for a return URL. Happily in a previous version of the Buy Now button form, there used to be, and the value still works. You simply need to add this line to your form (substituting in the appropriate return URL of course!).<input type="hidden" name="return" value="http://nettuts.com/payment-complete/">
Step 5
Since that PayPal button is pretty ugly, I'm also going to switch back to a regular submit button. To do this we simply swap the<input type='image'> element with a regular <input type='submit'> element, like this:
<input type="submit" value="Pay with PayPal!">
Step 6
Make a Donation to NETTUTS
Fill out the form and send us a few dollars for your favourite tutorial:
So there you have it. In the somewhat silly example above I've used two <select> fields. You could of course use regular text fields or really any combination. You can even leave fields out, for example it's not really necessary to have the item_number and item_name in my example.
If you fill out the form and press Pay, you'll see where the three inputs appear in PayPal - don't worry you don't need to actually pay!
Here's the final code I used:
<p><big><b>Make a Donation to NETTUTS</b></big><br />
Fill out the form and send us a few dollars for your favourite tutorial:</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="accounts@freelanceswitch.com">
<strong>Donation / Contribution? </strong><br />
<select name="item_name">
<option value="Donation">Donation</option>
<option value="Contribution">Contribution</option>
</select>
<strong>Which tutorial are you donating for?</strong><br />
<select name="item_number">
<option value="PayPal Form Tutorial">The PayPal Form Tutorial</option>
<option value="Amazon S3 Tutorial">The Amazon S3 Tutorial</option>
<option value="Some Other Tutorial">Some Other Tutorial</option>
</select>
<strong>How much do you want to donate?</strong><br />
$ <input type="text" name="amount">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="AU">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="return" value="http://nettuts.com/payment-complete/">
<br /><br />
<input type="submit" value="Pay with PayPal!">
</form>
Comments
Leave a CommentAdd a Comment











Jason
April 22nd, 2008
This is going to be so helpfull in my new site, i love your other site and now with the introduction of nettuts it will help alot of people understand the web more without confusing you to much. thanks guys
jerry
April 22nd, 2008
1st !!! :-))
giackop
April 22nd, 2008
hey first one ever to make a comment here!! i was making this button some days ago.. it’s not that easy so thanx for the tutorial!!!
Paulo Couto
April 22nd, 2008
Great article. The time it’s perfect since i’m building one of these forms for my site. Thank’s.
Mikael
April 22nd, 2008
Wow… Its a great honor to be the first to make a comment here and be the first to subscribe to the feed! Can’t wait to see what you’ll make of this site.
ali
April 22nd, 2008
woot first to comment on the first ever comment
ali
April 22nd, 2008
and good site. good on the old hue & saturationing the entire psdtuts template.
Razvan
April 22nd, 2008
Very useful, thanks!
Mark
April 22nd, 2008
Brilliant first TUT!! Good Shizzle!
Bernd
April 22nd, 2008
Very cool idea for this site. I love PSDTUTS but as a webdesigner myself I´m really happy to see a more web-centered site.
This article is something I`ve been looking after. Very helpful. I will implement this on my own blog: http://blog.rooocktar.com
Thanks!
Bernd
Martin
April 22nd, 2008
Good Tut. But: Is it possible to hide your paypal-account-name (your E-Mail), because we get a lot of spam to the paypal E-mail-Account.
Greetz from Germany
Martin
LongyZ
April 22nd, 2008
At the bottom, in NOTE: it still says ‘here at PSDtuts we use gravatars…’ shouldn’t it be nettuts?
Ewan
April 22nd, 2008
Yay, nettuts.com will be the best.
Nice article too.
LOSWL
April 22nd, 2008
First of all, congrats on the new website, it is looking slick!! and I love the calm colors :o)….Love this Paypal tut, one of the things I always wanted to know, thanks.
D. Carreira
April 22nd, 2008
Thanks for this tutorial! PSDTUTS and NETTUTS 4ever
David Carreira
1984
April 22nd, 2008
I am french!
Are tutorials CSS et XHTLM good on its French site?
PS: Is that one day NETTUTS and PSDTUTS will be translated into several languages ? (Especially in french.
)
Because at present I am obliged to go through Google translation to translate your site.
D. Carreira
April 22nd, 2008
Eih! “We use Gravatars on PSDTUTS, they are little icons that appear next to your name on this site and on many others. You can get a Gravatar account for free and any other site that supports it will show your avatar too!”
I think you should change this to: “We use Gravatars on NETTUTS, they are little icons that appear next to your name on this site and on many others. You can get a Gravatar account for free and any other site that supports it will show your avatar too!”
David Carreira
Micheal
April 22nd, 2008
Is there a way to know who has donate in your website?
shiva
April 22nd, 2008
Just great!
Mihai
April 22nd, 2008
Great job guys.Hope to see useful stuff here too.Good luck!
Spike
April 22nd, 2008
looks great thank you so much !
Michael_C
April 22nd, 2008
Sorry if im being stupid here but what is the “return URL” in step 4 for? I have a feeling the answer is going to be simple but what the hey!
Brian
April 22nd, 2008
Great tut Collis. I’ll probably add this in to my site soon now that I know how to make it pretty customizable.
Conrad
April 22nd, 2008
Aw.. nice tut. Gonna play with it later on and see how it works. Hated that Paypal button with all my guts. Thanks
Johan
April 22nd, 2008
Thanks, will check it out when i get home.
Enes Kaya
April 22nd, 2008
Thank very much, I’m so excited about the coming tutorials…
Ron
April 22nd, 2008
Wow. This is cool. I have searched for “useful” tutorials all over the net. Nothing are really that helpful in real life. I love this site and PSDTUTS.
Andrew D
April 22nd, 2008
Awesome great tutorial!
Gilbert Pellegrom
April 22nd, 2008
Thanks for that. Very useful.
Geoff
April 22nd, 2008
Glad to see a tut site for strictly web. How about a tut on creating email/newsletter lists?
Tom
April 22nd, 2008
Nice tutorial, I’ve already customized the paypal donation form some time ago, but this hints are definitely useful.
LouieP
April 22nd, 2008
nice tut, and hi to the new web
lol> NOTE:We use gravatars on PSDTUTS….. :p
Alex
April 22nd, 2008
Sorry guys, but allow to take pride in being your first subscriber!
Radek Mackowiak
April 22nd, 2008
Thanks for this. Following you on twitter
Rodney
April 22nd, 2008
Woah! Thanks again team for the wonderful addition to the family. If the quality of tuts at Psd are anything to go by, then this will be the best addition to the web! well done people!!!
Nathan
April 22nd, 2008
Thanks for this Collis, it will help me out for my next client.
Ben Griffiths
April 22nd, 2008
This is good - paypal can be awkward at times, this makes it seem a much simpler process!
Jonny McGurn
April 22nd, 2008
Nice tutorial, I remember the first time i attempted this, it was a night mare!…
Maybe you could add a PHP section? Youd get plenty of submissions from me then.
Tony
April 22nd, 2008
Excellent and very timely! I’m current working on a project that includes paypal and I too hate those ugly buttons. Thanks!
BrettJohn
April 22nd, 2008
Great tuts! thank you thank you thank you
david
April 22nd, 2008
i wished that this website was flash tutorial….
schoenling128
April 22nd, 2008
I really love the idea to show tutorials about the web in such a simple form.
THANK YOU!
mfg
Ivan
April 22nd, 2008
Nice article…
Serpentemx
April 22nd, 2008
You’re great man, keep it up dude, you’re the best.
rob
April 22nd, 2008
With the success of PSDTUTS, I can’t wait to see how this “sister” site develops.
Looking forward to it…
Marcus
April 22nd, 2008
I’m so glad that there is now a site I can rely on for up-to-date we tutorials! I can’t wait to see what other tutorials people come up with!
Harry
April 22nd, 2008
Awesome Tut , Awesome site
Colin Stein
April 22nd, 2008
now to find something people wanna pay me for….nakedcolin.com? anyone?
Daniel
April 22nd, 2008
very useful tutorial! and congrats for the launching of your new site!
Sr. Santana
April 22nd, 2008
Nettuts is the best news of the day. Nice article.
Great!!
Shane
April 22nd, 2008
Interesting article - it certainly seems simpler to integrate PayPal into a site than it does WorldPay or Barclays EPDQ (here in the UK).
I’ve bookmarked this one - despite the issues you refer to, it’s a quick and relatively simple way to accept payment.
Lamin Barrow
April 22nd, 2008
Keep the good stuff coming.
Might i ask, would there be any tutorial focused on Microsoft ASP.Net and related technologies?
Zane
April 22nd, 2008
@ Michael_C
The return url is so after they complete the paypal donation, they are linked back to your site. Also if they decide to cancel they are linked back as well
OrganicPixels
April 22nd, 2008
Looking forward to this site!
Danny
April 22nd, 2008
Nice first tutorial, love it
xaralee
April 22nd, 2008
WOW…
This is what i’m waiting for…
Will check it out daily
JPH
April 22nd, 2008
Great tutorial - and fantastic new site.
Michael Castilla
April 22nd, 2008
Very helpful. I know I’ll be needing this on the new WPCandy, so thanks!
Nico
April 22nd, 2008
First tutorial already amazing! Thanks!
lawrence
April 22nd, 2008
Love the tutorial, simple and to the point. Maybe you can do a follow up with the javascript validation..
Jonathan Solichin
April 22nd, 2008
That’s a great first start here. Good luck on whatever is next!
lawton chiles
April 22nd, 2008
I wanted to style my own Aweber form, aweber is a mailing list form for opt ins.
I have the code and i guess i could put it into dw. but I want it to look groovy.
So, i ask you kind sir, can you help us out?
Joefrey Mahusay
April 22nd, 2008
Thanks Collis for this tutorial. I need to use this in the future..Nice site.
Nick
April 22nd, 2008
Wow! Great idea! I’ll be adding this to my daily RSS feeds.
MacTyler
April 22nd, 2008
I have always wished that you guys would make a site like this, totally awesome!
Mike Smith - Bootstrapping Blog
April 22nd, 2008
Awesome article.
For those who are looking to have your paypal address hidden, the paypal button creator does offer you an encrypted code. However, after doing this, it’s pretty much impossible to change anything as it’s about 1,000,000 characters long of gibberish
alvarocker
April 22nd, 2008
Congrats for the new project, I’ll send you some tuts.
nitos
April 22nd, 2008
yay!!!!
thanks for this website!!
Qbrushes
April 22nd, 2008
i can’t remember sending a tutorial request! this is exactly what i need for my in progress project! i’m not kidding!
thanks alot.
Doveshead
April 22nd, 2008
Excellent site! Thank you so much!
Hope Nettuts will be as great as psdtuts!!!
Doveshead
April 22nd, 2008
Two sites give people who engage in web design and web development so many helps!
Many thanks again!
Alberto
April 23rd, 2008
Nice start, thank you!
Jash Sayani
April 23rd, 2008
Thanks man !
That was great !
Just a question….
Do I need to subscribe to NETTUTS when I have already Subscribed to PSDTUTS ?
You can reply via Twitter!
http://twitter.com/jashsayani
ArkRep
April 23rd, 2008
Great Tut,
Looking forward to more..
Ark
Adam
April 23rd, 2008
Very useful, thanks
Chandrashekar
April 23rd, 2008
That was a really nice tut. But one thing.. the form codes that you showed were that of an unsecure PayPal payment form. Now, guys, for tutorial purposes, I really think this is a great one. However, practically speaking, if you were gonna use this kind of form (just because you hate the PayPal button as much as I do, too!) people are going to look at your page-source (at the “” part) and then go directly to the return page (looking at the thingy)…
So guys, be careful, be intelligent and encrypt. But then, someone’s gotta find out a way to use CUSTOMIZED buttons like on this site even for encrypted PayPal forms!!
Thanks for the tut, anyway! And I am one of those die-hard fans of PSDTUTS… and will be of NETTUTS too!
Phil Brown
April 23rd, 2008
Hey, great tutorial. I don’t see a Legend, Fieldset or labels for those input fields though…maybe one for another tutorial.
RicardoSantin
April 23rd, 2008
Hi, first congratulations for the new Website, think it will be very helpful for developer…
Second y use to work with flash so i would liki to lern how to do the payment with Action Script. thanks.
Qbrushes
April 23rd, 2008
it would be awesome if design elements made in PS is mixed with CSS How to.. that would totally be unique!
Toan
April 24th, 2008
Great!!!
Zomball
April 24th, 2008
Great tutorial and looking forward to watching the site develop. I’m a big fan of PSDTUTS so hoping the new venture is just as successful.
Cheers!
FlashRipper
April 24th, 2008
Thanks, you! Very cool
Christian Mejia
April 24th, 2008
I was fortunate to learn this on my own but I tell you what… I wish this tutorial was available when I was trying to learn it. It would have saved me a lot of headaches. Glad it’s up now for our fellow designers who will benefit from it! I’m really digging Nettuts massively.
Brian
April 24th, 2008
FLATUTS next?! PLLLLLLLLEASE!!!!!!
Leland Clemmons
April 25th, 2008
Great tutorial, always wanted to learn how to do this! Wouldn’t it be easier to use radio buttons for the “Donation/Contribution?” part, though?
James Mitchell
April 26th, 2008
Thanks for the tut. As a good supplement to this article, I read one for receiving unique payments. I find it useful for web hosting, design, and my other kind of stuff.
Receiving Unique Payments with Paypal by Marc Amos.
Razvan
April 27th, 2008
Thanks for the link James!
Michael_C
April 30th, 2008
@ Zane
Thanks man
Blue Buffalo
April 30th, 2008
Very Nice! It’s cool to see new ways to tweak PayPal code. Thanks!
Avangelist
May 1st, 2008
hmmm, what you have just done is a guide to designing html forms, the inclusion of paypal is irrelevant but a good device to provide as an example.
How do you style the form without a table, and without ID or class tags?
That’s the next bit I would like to know.
Karl Hardisty
May 3rd, 2008
Good stuff. As above though, I would really recommend encrypting the content.