FORCING THE BUYER TO CHOOSE BETWEEN STYLES, COLORS, OR PRICE - Aug 2nd, 2013


Taking the example above one step further, let’s say you wanted to let buyers choose between sizes and have the price
for that size automatically populate your PayPal cart.

Here’s an approach that I used with a multi record section editor, that also let’s you force the buyer to make
required choice(es) before they can submit their order to PayPal.

The fields in the multi record section editor used in the form were category, stock number, 8 ounce price, 16 ounce
price and 64 ounce price. If statements were used to allow a size option to not appear on the web page if the price is
not entered in the editor.

The onsubmit in the second line tests whether the choice has been made.

Continue shopping returns the buyer back to the page where they placed the order from.



<form name='cart101' action="https://www.paypal.com/cgi-bin/webscr" method="post"
onsubmit="return PackageForm(this);">

<input type="hidden" name="business" value="payments@yourdomain.com">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="shopping_url" value="<?php echo thisPageUrl() ?>">
<input type="hidden" name="add" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="cpp_header_image" value="http://mysite/<?PHP echo $paypalRecord['pplogo'] ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn value" value="PP-ShopCartBF">
<input type="hidden" name="alt" value=”<?php echo $record['category'] ?><?php echo $record['stock_ number'] ?>">
<input type="hidden" name="item_name" value="<?php echo $record['category'] ?> <?php echo $record['stock_number'] ?>">

<input type="hidden" name="xxx">
<select name="amount" style="width:150px;font:9px;margin-top:4px">
<option selected>Select a Size</option>
<?php if ($record['8_oz_price']): ?><option value="<?php echo $record['8_oz_price'] ?>">8 Ounce Size - <?php echo
$record['8_oz_price'] ?></option><?php endif ?>
<?php if ($record['16_oz_price']): ?><option value="<?php echo $record['16_oz_price'] ?>">16 Ounce Size - <?php echo
$record['16_oz_price'] ?></option><?php endif ?>
<?php if ($record['64_oz_price']): ?><option value="<?php echo $record['64_oz_price'] ?>">64 Ounce Size - <?php echo
$record['64_oz_price'] ?></option><?php endif ?>
</select><br />

<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but10.gif"
name="submit"
alt="Make payments with PayPal - it's fast, free and secure!">
</form>



Here’s the javascript that goes into the body of the page to execute the validation tests.

The “select name” variable “amount” is the one that is passed to PayPal if a selection is made.

If you need more tests, add more unique variables.

Remember that the “select name” variable is the one that gets sent to PayPal and the “name” variable is used to
test the condition. They can not be identical. in this case the names are os1 and os2



<script type="text/javascript" language="JavaScript">
function PackageForm(frm) {
var emsg = '';

//Review all your form fields that you want to require.
//add your error message to the "emsg" variable.

//fires required field (os1)
var i = frm.os1.selectedIndex;
if (i == 0) {
emsg += "Please tell us where you heard about us.\n";
}


//second required field (os2)
var i2 = frm.os2.selectedIndex;
if (i2 == 0) {
emsg += "Please select a color\n";
}

//if emsg is empty, the Order is OK, so proceed to PayPal. ELSE
//if emsg is NOT empty, show error message(s).
if (emsg == '') {
return true;
}else {
alert(emsg);
return false;
}
}
</script>




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service