Using smd_each to produce custom select boxes
Jan 14, 03:28 AMHere’s another potentially-interesting Textpattern form, this one for a PayPal shopping cart. It pulls articles with a number of custom fields (for things like price and shipping weight) and uses smd_each to generate select boxes for sizes.
For the most part, this is pretty straightforward. PayPal will generate most of it for you from your merchant account, then it’s just a matter of throwing Textpattern tags where you need them and styling as appropriate.
My favorite part comes near the beginning. This uses smd_each to generate
<txp:if_custom_field name="sizes">
<p class="storesize"><strong>Size:</strong> <select name="item_name">
<txp:smd_each include="sizes" subset="2">
<option value="<txp:title /> {var_value}">{var_value}</option>
</txp:smd_each>
</select></p>
The complete form is below; it uses several of custom fields, most of them with names like “(Store) Something” to help my client remember what they’re used for (“sizes” doesn’t look like that because smd_each doesn’t seem to like custom fields with special characters or spaces—at least, I had problems with them during testing).
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" class="paypalbutton"><input type="hidden" name="add" value="1" /> <input type="hidden" name="cmd" value="_cart" /> <input type="hidden" name="business" value="store@example.com" /><txp:if_custom_field name="sizes"> <p class="storesize"><strong>Size:</strong> <select name="item_name"> <txp:smd_each include="sizes" subset="2"> <option value="<txp:title /> {var_value}">{var_value}</option> </txp:smd_each> </select></p><txp:else /> <input type="hidden" name="item_name" value="<txp:title no_widow="0" />" /> </txp:if_custom_field><input type="hidden" name="amount" value="<txp:custom_field name="(Store) Price" default="100" />" /> <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="weight" value="<txp:custom_field name="(Store) Shipping Weight" default="20" />" /> <input type="hidden" name="weight_unit" value="lbs" /> <input type="hidden" name="lc" value="US" /> <input type="hidden" name="bn" value="PP-ShopCartBF" /> <p><input class="ppbutton" type="image" src="/img/addtocart-trans.png" name="submit" alt="PayPal - The safer, easier way to pay online!" /></p> <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" /> </form>












