Functions:addressStateOptions

From Whirlwind eCommerce Wiki
Revision as of 13:38, 21 October 2008 by Root (Talk | contribs)

Jump to: navigation, search
Page Template Managers
Page Template Managers

Page Template Functions

Description

Retrieves US states in a string of >option< tags.

Syntax

$stateOptionsString = eV::addressStateOptions($selection);

Paramaters

  • $selection STRING (optional)
2-character state that will be 'selected' from the options

Return Values

STRING of >option< tags.

Examples

Simple example
// retrieve option sting
$optionString = eV::addressStateOptions();
 
// output form
echo "<form action=\"index.php\" method=\"post\">";
 
// output optionString inside of state select
echo "<select name=\"state\">" . $optionString . "</select>";
 
// rest of form
echo "<input type=\"submit\" value=\"Post\">";
echo "</form>";
Complex example using state generated by Functions:userAddressAddEdit:userAddressAddEdit
// init vars
// expects addressId to be passed,
// if not set to 0 which will be treated as creating a new address for the user
if(!isset($attributes['addressId']) $attributes['addressId'] = 0;
 
// init address add/edit function
$addr = eV::userAddressAddEdit("firstName,lastName,street1,city,state,zipCode",$attributes['addressId']);
// lets shortcut the values
$addrVals = $addr['values'];
 
// if userAddressAddEdit returned array is empty
// than its in invalid attempt to access an address
// that does not belong to the current user
// so kick em out
if(!count($addr['values'])) eV::redirect('index.php?message=Invalid address access attempt');
 
// lets get the states option
// making sure to pass the addr state value so it is $addrVals['value']['state']);
 
// if a message is passed, output it
// this is used to notify the user of missing fields, invalid values
if(!empty($addr['message'])) echo "<br>" . $addr['message'] . "<br>";
 
// output the form
echo "<form action=\"index.php\" method=\"post\">";
echo "First Name: <input type=\"text\" name=\"firstName\" value\"" . $addrVals['firstName'] . "\" size=25 maxlength=100>";
echo "<br>Last Name: <input type=\"text\" name=\"lastName\" value\"" . $addrVals['lastName'] . "\" size=25 maxlength=100>";
echo "<br>Street: <input type=\"text\" name=\"street1\" value\"" . $addrVals['street1'] . "\" size=25 maxlength=100>";
echo "<br>City: <input type=\"text\" name=\"city\" value\"" . $addrVals['city'] . "\" size=25 maxlength=100>";
echo "<br>State: <select name=\"state\">" . $stateOptions . "</state>";
echo "<br>Zip: <input type=\"text\" name=\"zipCode\" value\"" . $addrVals['zipCode'] . "\" size=8 maxlength=5>";
echo "<br><input type=\"submit\" value=\"go!\">";
 
// these attributes must be passed with this form for userAddressAddEdit to work correctly!
echo "
<input type=\"hidden\" name=\"addressId\" value=\"" . $addrVals['addressId'] . "\">
<input type=\"hidden\" name=\"formAction\" value=\"form\">
<input type=\"hidden\" name=\"pageId\" value=\"$pageId\">
";
 
// close out our form
echo "</form>";