Functions:userAccountEdit

From Whirlwind eCommerce Wiki
Jump to: navigation, search

Description

Controls an "edit user form" which edits user account info. Use this function to build an 'edit account' page.

Syntax

$accountArray = eV::userAccountEdit($fieldList,$redirect[,$userId]);

Paramaters

  • $fieldList STRING
Comma separated list of fields to be managed by the form.
Available fields to place in $fieldList:
  • User Account Fields
  • emailAddress
  • firstName
  • lastName
  • password
  • passwordConfirm
  • userNotes
  • company
  • title
  • Other Fields
  • subscribe: if set to 1, newsletter registration process will be initiated for the passed emailAddress
  • captcha: verifies captcha validation has been passed
  • custom_field_...: any number of custom user fields can be passed, but must be set up in Settings in User Management.
Example $fieldList value: "firstName,lastName,emailAddress,password,passwordConfirm"
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: "emailAddress/email:You must enter an valid email/unique:An account already exists with that email address - please select another,password/min:8:You must enter a password of at least 8 characters"
note that the messages in control fields cannot contain comma (,), slash (/) or colon (:) as these have special meaning to the processing function
  • $redirect STRING
URL where visitor will be forwarded to following a successful form submission
  • $userId INT OPTIONAL
Unique system assigned user id. defaults to the user id for the current logged in user. Only pass if you want to create a form to manage a user account other than the logged in user.

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 and [customFieldTags]: a keyed array of HTML field code for each custom field - this allows for easy creation of entire custom field tags simply by echo'ing the values in this array:

Array
(
    [message] => STRING
    [values] => ARRAY
        (
           //User Account Fields
           [firstName] => STRING
           [lastName] => STRING
           [emailAddress] => STRING
           [password] => STRING
           [passwordConfirm] => STRING
           [userNotes] => STRING
           [company] => STRING
           [title] => STRING
           //Custom Fields
           [custom_field_...] => STRING
           ...
        )
    [customFieldTags] => ARRAY
        (
           //custom fields for users
           [custom_field_x] => STRING
           [custom_field_y] => STRING
           ...
        )
)

Examples

Simple 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.
eV::authorizeIsLoggedIn('index.php?message=You must be logged in to edit your account info');
 
// create account function
$account = eV::userAccountEdit("emailAddress/email:You must enter a valid email address/unique:The email address you entered is already in use - please select another,password/min:8:Your password must be at least 8 characters long,passwordConfirm","index.php?message=Your account has been updated!");
 
// shortcut the elements of the userAccountEdit array
$accVals = $account['values'];
$accCust = $account['customFieldTags'];
 
// display the message (if applicable)
// this message is generated by the userAccountEdit function
// not to be confused with the global $message attribute 
// you probably want to accomidate both
if(!empty($account['message'])) echo $account['message'];
 
// here is the global message
if(!empty($message)) echo $message;
 
// output page content
echo "$title
<br>$subTitle
<br>$copy";
 
// start the form
echo "<form name=\"editAccountForm\" action=\"index.php\" method=\"post\">";
 
// note when calling userAccountEdit you can specify the fields, so the below fields may vary
// make sure you call all, and only the fields you need
 
// email address
// recommend using htmlspecial chars to ensure quotes and carots don't disrupt the form tag
echo "<br>Email Address: <input name=\"emailAddress\" maxlength=100 maxlength=255 value=\"" . htmlspecialchars($accVals['emailAddress']) . "\" type=\"text\" />";
 
// password and confirm password will be compared upon submission to match
// they must also be min 8 characters in length
echo "<br>Password: <input name=\"password\" type=\"password\" value=\"" . htmlspecialchars($accVals['password']) . "\" maxlength=50/>";
echo "<br>Confirm Password: <input name=\"passwordConfirm\" type=\"password\" value=\"" . htmlspecialchars($accVals['passwordConfirm']) . "\" maxlength=50/>";
 
// submit form button
echo "<br><input type=\"submit\" value=\"Edit!\">";
 
// required hidden field - must pass this page id so submissions reload in this page
echo "<input type=\"hidden\" name=\"pageId\" value=\"" . $attributes['pageId'] . "\">";
 
// end the form
echo "</form>";
Full 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.
eV::authorizeIsLoggedIn('index.php?message=You must be logged in to edit your account info');
 
// edit account function
$account = eV::userAccountEdit("emailAddress/email:You must enter a valid email address/unique:The email address you entered is already in use - please select another,firstName,lastName,title,password/min:8:Your password must be at least 8 characters long,passwordConfirm,subscribe,captcha,custom_field_x,custom_field_y,custom_field_z","index.php?message=Your account has been updated!");
 
// shortcut the elements of the userAccountEdit array
$accVals = $account['values'];
$accCust = $account['customFieldTags'];
 
// display the message (if applicable)
// this message is generated by the userAccountEdit function
// not to be confused with the global $message attribute 
// you probably want to accomidate both
if(!empty($account['message'])) echo $account['message'];
 
// here is the global message
if(!empty($message)) echo $message;
 
// output page content
echo "$title
<br>$subTitle
<br>$copy";
 
// start the form
echo "<form name=\"editAccountForm\" action=\"index.php\" method=\"post\">";
 
///////////////////////////////
////// CORE form fields ///////
///////////////////////////////
 
// note when calling userAccountEdit you can specify the fields, so the below fields may vary
// make sure you call all, and only the fields you need
 
// email address
// recommend using htmlspecial chars to ensure quotes and carots don't disrupt the form tag
echo "<br>Email Address: <input name=\"emailAddress\" maxlength=100 maxlength=255 value=\"" . htmlspecialchars($accVals['emailAddress']) . "\" type=\"text\" />";
// newsletter subscribe field
// checking this will trigger the newsletter registration process in addition to creating an account
echo "<br>Join Our Newsletter: <input name=\"subscribe\" type=\"checkbox\" checked=\"checked\" value=\"1\"/>";
 
echo "<br>First Name: <input name=\"firstName\" type=\"text\" maxlength=50  value=\"" . htmlspecialchars($accVals['firstName']) . "\" />";
echo "<br>Last Name: <input name=\"lastName\" type=\"text\" maxlength=50  value=\"" . htmlspecialchars($accVals['lastName']) . "\" />";
 
// password and confirm password will be compared upon submission to match
// they must also be min 8 characters in length
echo "<br>Password: <input name=\"password\" type=\"password\" value=\"" . htmlspecialchars($accVals['password']) . "\" maxlength=50/>";
echo "<br>Confirm Password: <input name=\"passwordConfirm\" type=\"password\" value=\"" . htmlspecialchars($accVals['passwordConfirm']) . "\" maxlength=50/>";
 
// user custom fields
// these custom fields must be created in Settings > User Management
// and must be specified in the fieldList attributes of the userAccountEdit function
// custom fields are included in the customFieldTags key of the returned userAccountEdit array
// the contents of the customFieldTags elements are full tags for the field as set in field settings for the field in Settings > User Management
// you can simply output the customFieldTags element contents for the field
echo "<br>Custom Field X: " . $accCust['custom_field_x']);
echo "<br>Custom Field Y: " . $accCust['custom_field_y']);
echo "<br>Custom Field Z: " . $accCust['custom_field_z']);
 
// captcha verification
// great to keep ppl from using bots to abuse the system
// this is not required to use, but you must have 'captcha' in the fieldList attribute of the userAccountEdit function
// 3 things required for this to work:
// 1. 'captcha' in the fieldList of the userAccountEdit
// 2. calling on the captcha image by setting $CaptchaImgSrc as the image source
// 3. including the captcha form field
echo "<br>Captcha Validation <img src='$CaptchaImgSrc'>
<br>Please type in the characters you see above: <input type=text name=captcha value='' size=10 maxlength=10>";
 
// submit form button
echo "<br><input type=\"submit\" value=\"Edit!\">";
 
// required hidden field - must pass this page id so submissions reload in this page
echo "<input type=\"hidden\" name=\"pageId\" value=\"" . $attributes['pageId'] . "\">";
 
// end the form
echo "</form>";