Functions:userAddressAddEdit

From Whirlwind eCommerce Wiki
Jump to: navigation, search

Description

Controls an address form which adds and edits user account info. Use this function to build an 'address book management' page.

Syntax

$addressForm = eV::userAddressAddEdit($fieldList);

Paramaters

  • $fieldList
Comma separated list of fields to be managed by the form.
Available fields to place in $fieldList:
  • addressName
  • firstName
  • lastName
  • company
  • street1
  • street2
  • city
  • state
  • state_alt
  • zipCode
  • country
  • phone1
  • phone2
  • phone3
  • fax
Example $fieldList value: "firstName,lastName,street1,street2,city,state,zipCode"
The listed fields in $fieldList can be complimented with the following field controls:
  • /min:#:message
  • /max:#:message
  • /default:value
  • /email:message
  • /unique:message
example use of controls in $fieldList: "firstName/min:1:You must enter first name,lastName/min:1:You must enter a last name"
note that the messages in control fields cannot contain comma (,), slash (/) or colon (:) as these have special meaning to the processing function

Return Values

Multidimensional array of field values and error messages containing [message]: a string containing any error messages that prohibited the form data from being submitted, and [values]: a keyed array of fields and their values. Note that only fields specified in the $fieldList attribute will be contained in the [value] array:

Examples

example
// kick if logged out 
// recommended to place in 'pre process' code of template
// no reason to waste processing power if we just gonna kick to home.
authorizeIsLoggedIn("/index.php?message=You must be logged in to manage your address book");
 
// required fields - tell the system what do do with what address
// addressId can be passed via URL (querystring) or FORM (post)
// sets the address that will be managed. Set as 0 for a new address
if(!isset($_REQUEST['addressId'])) $_REQUEST['addressId'] = 0;
// formAction tells the system weather we are adding (new) or editing (query) an address
// default to 'new', set to 'query' if you are editing an existing address
if(!isset($_REQUEST['formAction'])) $_REQUEST['formAction'] = 'new';
// userAddressAddEdit will have access to the addressId and formAction request variables
 
// this function will actually post the form
$addressFormArr = eV::userAddressAddEdit('addressId,emailAddress,firstName/min:1:You must enter a first name,lastName/min:1:You must enter a last name,street1/min:1:You must enter a street address,street2,city/min:1:You must enter a city,state,state_alt,zipCode/min:1:You must enter a postal code,country,phone1/min:1:You must enter a phone number,company');
 
// shortcut the returned arrays
$addVals = $addressFormArr['values'];
$addMsg = $addressFormArr['message'];
 
// quick and ez state and country options
$stateOptions = eV::addressStateOptions($addVals['state']); // returns string of option tags for states
$countryOptions= eV::addressCountryOptions($addVals['country']); // returns string of option tags for countries
 
 
// output page controlled content
echo "$title
<br/>$subTitle
<br/>$copy";
 
// global message
if(!empty($message)) echo $message;
 
// userAddressAddEdit error message
if(!empty($addMsg)) echo $addMsg;
 
// start address form
echo "<hr><form name=\"addressForm\" action=\"index.php\" method=\"post\">";
// use htmlspecial chars to make sure characters that could adversely effect the form field are converted (>"'<...etc)
echo "<br>Email Address: <input name=\"emailAddress\" maxlength=100 value=\"" . htmlspecialchars($addVals['emailAddress']) . "\" type=\"text\" />";
echo "<br>First Name: <input name=\"firstName\" value=\"" . htmlspecialchars($addVals['firstName']) . "\" type=\"text\" maxlength=50/>";
echo "<br>Last Name: <input name=\"lastName\" value=\"" . htmlspecialchars($addVals['lastName']) . "\" type=\"text\" maxlength=50/>";
echo "<br>Company: <input name=\"company\" value=\"" . htmlspecialchars($addVals['company']) . "\" type=\"text\" maxlength=50/>";
echo "<br>Street 1: <input name=\"street1\" value=\"" . htmlspecialchars($addVals['street1']) . "\" type=\"text\" maxlength=100/>";
echo "<br>Street 2: <input name=\"street2\" value=\"" . htmlspecialchars($addVals['street2']) . "\" type=\"text\" maxlength=100/>";
echo "<br>City: <input name=\"city\" value=\"" . htmlspecialchars($addVals['city']) . "\" type=\"text\" maxlength=50/>";
echo "<br>State: <select name=\"state\" >" . $stateOptions . "</select>";  
 
// state alt only necessary if using countried other than USA, to support other country states, provences etc.      	
echo "<br>State Alt: <input name=\"state_alt\" value=\"" . htmlspecialchars($addVals['state_alt']) . "\" type=\"text\" maxlength=50/>";
 
echo "<br>Zip Code: <input name=\"zipCode\" value=\"" . htmlspecialchars($addVals['zipCode']) . "\" type=\"text\" size=\"10\" maxlength=\"10\"/>";
echo "<br>Country: <select name=\"country\">" . $countryOptions; . "</select>";
echo "<br>Phone: <input name=\"phone1\" value=\"" . htmlspecialchars($addVals['phone1']) . "\" type=\"text\" />";
 
// submit button
echo "<br><input type=\"submit\" value=\"Post Address\">";
 
// required hidden fields
echo "<input type=\"hidden\" name=\"addressId\" value=\"" . htmlspecialchars($addVals['addressId']) . "\">
	<input type=\"hidden\" name=\"formAction\" value=\"form\">
	<input type=\"hidden\" name=\"pageId\" value=\"$pageId\">";
 
// exitLocation field tells system where to go after form is succesfully submitted
// usu just want to go back into the address management form
echo "<input type=\"hidden\" name=\"exitLocation\" value=\"index.php?pageId=$pageId&message=Changes to your address book have been posted\">";
 
// close out form
echo "</form>";
example 2

See Page Templates:Creating a Address Book Management Template for an example of integrating the address selection and address form in the same template/page.