Functions:addressCountryOptions

From Whirlwind eCommerce Wiki
Revision as of 19:00, 19 February 2009 by 71.163.185.8 (Talk) (Return Values)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Page Template Managers

Page Template Functions

Description

Retrieves countries in a string of >option< tags.

Syntax

$countryOptionsString = eV::addressCountryOptions($selection);

Paramaters

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

Return Values

STRING of <option> tags.

Examples

Simple example
// retrieve option sting
$optionString = eV::addressCountryOptions();
 
// output form
echo "<form action=\"index.php\" method=\"post\">";
 
// output optionString inside of country select
echo "<select name=\"country\">" . $optionString . "</select>";
 
// rest of form
echo "<input type=\"submit\" value=\"Post\">";
echo "</form>";
Complex example using country 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,country",$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 options
// making sure to pass the addr state value so it is 'selected' out of the options
$stateOptions = eV::addressStateOptions($addrVals['state']);
 
 
// lets get the country options
// making sure to pass the addr country value so it is 'selected' out of the options
$countryOptions = eV::addressCountryOptions($addrVals['country']);
 
// 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>Country: <select name=\"country\">" . $countryOptions . "</state>";
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>";