Prev | Current Page 620 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


{/if}



Name:


{if $obj->mNameError}

You must enter your name.


{/if}



Password:


{if $obj->mPasswordError}

You must enter a password.


{/if}



Re-enter Password:


{if $obj->mPasswordConfirmError}

You must re-enter your password.


{elseif $obj->mPasswordMatchError}

You must re-enter the same password.


{/if}


{if $obj->mEditMode}

Day phone:
CHAPTER 16 ?–  MANAGING CUSTOMER DETAILS 514

size="32" />



Eve phone:

size="32" />



Mob phone:

size="32" />


{/if}

|
Cancel

6. Create a new presentation object file named customer_details.php in the presentation folder, and
add the following to it:
class CustomerDetails
{
// Public attributes
public $mEditMode = 0;
public $mEmail;
public $mName;
public $mPassword;
public $mDayPhone = null;
public $mEvePhone = null;
public $mMobPhone = null;
public $mNameError = 0;
public $mEmailAlreadyTaken = 0;
public $mEmailError = 0;
public $mPasswordError = 0;
public $mPasswordConfirmError = 0;
public $mPasswordMatchError = 0;
public $mLinkToAccountDetails;
public $mLinkToCancelPage;
CHAPTER 16 ?–  MANAGING CUSTOMER DETAILS 515
// Private attributes
private $_mErrors = 0;
// Class constructor
public function __construct()
{
// Check if we have new user or editing existing customer details
if (Customer::IsAuthenticated())
$this->mEditMode = 1;
if ($this->mEditMode == 0)
$this->mLinkToAccountDetails = Link::ToRegisterCustomer();
else
$this->mLinkToAccountDetails = Link::ToAccountDetails();
// Set the cancel page
if (isset ($_SESSION['customer_cancel_link']))
$this->mLinkToCancelPage = $_SESSION['customer_cancel_link'];
else
$this->mLinkToCancelPage = Link::ToIndex();
// Check if we have submitted data
if (isset ($_POST['sended']))
{
// Name cannot be empty
if (empty ($_POST['name']))
{
$this->mNameError = 1;
$this->_mErrors++;
}
else
$this->mName = $_POST['name'];
if ($this->mEditMode == 0 && empty ($_POST['email']))
{
$this->mEmailError = 1;
$this->_mErrors++;
}
else
$this->mEmail = $_POST['email'];
// Password cannot be empty
if (empty ($_POST['password']))
{
$this->mPasswordError = 1;
$this->_mErrors++;
}
CHAPTER 16 ?–  MANAGING CUSTOMER DETAILS 516
else
$this->mPassword = $_POST['password'];
// Password confirm cannot be empty
if (empty ($_POST['passwordConfirm']))
{
$this->mPasswordConfirmError = 1;
$this->_mErrors++;
}
else
$password_confirm = $_POST['passwordConfirm'];
// Password and password confirm should be the same
if (!isset ($password_confirm) ||
$this->mPassword != $password_confirm)
{
$this->mPasswordMatchError = 1;
$this->_mErrors++;
}
if ($this->mEditMode == 1)
{
if (!empty ($_POST['dayPhone']))
$this->mDayPhone = $_POST['dayPhone'];
if (!empty ($_POST['evePhone']))
$this->mEvePhone = $_POST['evePhone'];
if (!empty ($_POST['mobPhone']))
$this->mMobPhone = $_POST['mobPhone'];
}
}
}
public function init()
{
// If we have submitted data and no errors in submitted data
if ((isset ($_POST['sended'])) && ($this->_mErrors == 0))
{
// Check if we have any customer with submitted email.


Pages:
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
kreator www Pozycjonowanie sem Odżywki strony