PayPal Hacks. 100 Industrial-Strength Tips and Tools Free Open Book

PayPal Hacks. 100 Industrial-Strength Tips and Tools

Previous Section  < Day Day Up >  Next Section

Hack 33 Include More Than Two Option Fields

figs/moderate.gif figs/hack33.gif

Give your customers a large selection of options when purchasing their items, despite the limitations of payment buttons.

PayPal buttons enable you to easily offer fixed products to your customers. Although some flexibility is provided in the form of option fields [Hack #32], PayPal currently supports only two such fields. If your product has more than two options (e.g., Size, Color, and Material), you can employ a little JavaScript code and a hidden field to create as many option fields as you need.

Start with the basic Buy Now button code [Hack #28] for a single item, although this works with Shopping Cart, Subscription, and Donation buttons as well:

<form action="https://www.paypal.com/cgi-bin/youbscr" method="post">

<input type="hidden" name="cmd" value="_xclick">

<input type="hidden" name="business" value="sales@payloadz.com">

<input type="hidden" name="item_name" value="Widget One">

<input type="hidden" name="item_number" value="Wid-001">

<input type="hidden" name="amount" value="1.00">

<input type="hidden" name="no_note" value="1">

<input type="hidden" name="currency_code" value="USD">

<input type="image" src=

                "https://www.paypal.com/en_US/i/btn/x-click-but23.gif" 

                border="0" name="submit>

</form>

Suppose the item you're selling has three options: Color, Size, and Material. You can provide three drop-down lists [Hack #32], one for each option, with which your customers can customize their purchases. To keep things simple, name your drop-down elements custom1, custom2, and custom3.

This code joins all three of the selected options into a single variable, custom, to be passed to PayPal. You'll need to add the custom form element to your button as a hidden variable with no value specified. The value will be populated by the JavaScript code when the form is submitted. Here's an HTML form with form options and the custom field:

Color 

<select name="custom1">

    <option value="White" selected>White</option>

    <option value="Grey">Grey</option>

    <option value="Black">Black</option>

</select>

<br>

Size 

<select name="custom2">

    <option value="Small">Small</option>

    <option value="Medium">Medium</option>

    <option value="Large" selected>Large</option>

    <option value="X-Large">X-Large</option>

</select>

<br>

Material 

<select name="custom3">

    <option value="Spandex" selected>Spandex</option>

    <option value="Cotton">Cotton</option>

</select>

<input type="hidden" name="custom" value="">

Figure 4-5 shows the additional custom fields in action. You can include as many option fields as you can fit on your page.

Figure 4-5. Including additional option fields
figs/pph_0405.gif


You can continue adding as many option fields as you need, provided that you use the same custom# naming format. Just be sure that the total character count for the labels and their possible variable values does not exceed 256 characters, the size limit of PayPal's custom variable.

Add the HTML code to your PayPal button form between the opening and closing <form> tags. Then add the following JavaScript code to the head of the web page:

<script language="JavaScript">

<!--

  function joinFields( ){

    fmBuy.custom.value = 'Color:' + fmBuy.custom1.value + ' Size:' +

              fmBuy.custom2.value + ' Material:' + fmBuy.custom3.value

  }

// -->

</script>

If you add additional fields, you'll need to modify this code to accommodate them.

Finally, add a call to the joinFields routine by inserting the name and onSubmit attributes to the existing <form> tag (the values for the action and method attributes remain unchanged):

<form action="https://www.paypal.com/cgi-bin/youbscr" method="post" 

name="fmBuy" onSubmit="joinFields( )">

Here is the final code for the example form:

<form action="https://www.paypal.com/cgi-bin/youbscr" method="post" name="fmBuy" 

onSubmit="joinFields( )">

<input type="hidden" name="cmd" value="_xclick">

<input type="hidden" name="business" value="sales@payloadz.com">

<input type="hidden" name="item_name" value="Widget One">

<input type="hidden" name="item_number" value="Wid-001">

<input type="hidden" name="amount" value="1.00">

<input type="hidden" name="no_note" value="1">

<input type="hidden" name="currency_code" value="USD">

  Color 

  <select name="custom1">

    <option value="White" selected>White</option>

    <option value="Grey">Grey</option>

    <option value="Black">Black</option>

  </select>

<br>

Size 

<select name="custom2">

    <option value="Small">Small</option>

    <option value="Medium">Medium</option>

    <option value="Large" selected>Large</option>

    <option value="X-Large">X-Large</option>

  </select>

<br>

Material 

<select name="custom3">

    <option value="Spandex" selected>Spandex</option>

    <option value="Cotton">Cotton</option>

  </select>

  <input type="hidden" name="custom" value="">



<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif"

                border="0" name="submit">

</form>

When the complete page is loaded (with the button code in the page body and the JavaScript in the page head), the customer-selected option fields will be concatenated into one string and passed through to PayPal in the custom variable. For instance, if the form is submitted with its default values, the custom variable will be set to Color:White Size:Large Material:Spandex. The string will appear in details of the transaction in your PayPal account; your customers will never see it. If necessary, you can also parse this field out in the IPN page [Hack #80] .

    Previous Section  < Day Day Up >  Next Section
    Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y]


         Main Menu
    PayPal Hacks
    Table of Contents
    Copyright
    Credits
    Preface
    Chapter 1. Account Management
    Chapter 2. Making Payments
    Chapter 3. Selling with PayPal
    Chapter 4. Payment Buttons
    Introduction: Hacks #28-44
    Hack 28 Create a Buy Now Button
    Hack 29 Use a Custom Button Image
    Hack 30 Create a Purchase Button for Services
    Hack 31 Create an Auction Payment Button
    Hack 32 Provide Purchase Options with Drop-Down Listboxes
    Hack 33 Include More Than Two Option Fields
    Hack 34 Override Shipping and Handling Preferences
    Hack 35 Build Notification Tracking
    Hack 36 Hack-Proof Your Payment
    Hack 37 Hack-Proof Your Buttons with Encryption
    Hack 38 Include Payment Buttons in Email Messages
    Hack 39 Hide Your Email Address from Spammers
    Hack 40 Accept Donations
    Hack 41 PayPal-Enable Your Flash
    Hack 42 Get More Out of Dreamweaver and PayPal
    Hack 43 Provide Options with ASP.NET Web Controls
    Hack 44 Try Accepting Payments in a Bogus Currency
    Chapter 5. Storefronts and Shopping Carts
    Chapter 6. Managing Subscriptions
    Chapter 7. IPN and PDT
    Chapter 8. The PayPal Web Services API
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele