From e2cb0b52aaa02a3f3f41d0df377d189529713738 Mon Sep 17 00:00:00 2001 From: wei <> Date: Thu, 10 May 2007 23:00:04 +0000 Subject: Update blog tutorial --- .../protected/pages/Day3/CreateNewUser.page | 120 ++++++++++----------- 1 file changed, 60 insertions(+), 60 deletions(-) (limited to 'demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page') diff --git a/demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page b/demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page index d9ef684f..77b97f7d 100644 --- a/demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page +++ b/demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page @@ -29,46 +29,46 @@ Based on the above analysis, we write the page template as follows: Username: <com:TRequiredFieldValidator - ControlToValidate="Username" - ErrorMessage="Please provide a username." - Display="Dynamic" /> + ControlToValidate="Username" + ErrorMessage="Please provide a username." + Display="Dynamic" /> <com:TCustomValidator - ControlToValidate="Username" - ErrorMessage="Sorry, your username is taken by someone else. Please choose another username." - OnServerValidate="checkUsername" - Display="Dynamic" /> + ControlToValidate="Username" + ErrorMessage="Sorry, your username is taken by someone else. Please choose another username." + OnServerValidate="checkUsername" + Display="Dynamic" />
<com:TTextBox ID="Username" />
Password: <com:TRequiredFieldValidator - ControlToValidate="Password" - ErrorMessage="Please provide a password." - Display="Dynamic" /> + ControlToValidate="Password" + ErrorMessage="Please provide a password." + Display="Dynamic" />
<com:TTextBox ID="Password" TextMode="Password" />
Re-type Password: <com:TCompareValidator - ControlToValidate="Password" - ControlToCompare="Password2" - ErrorMessage="Your password entries did not match." - Display="Dynamic" /> + ControlToValidate="Password" + ControlToCompare="Password2" + ErrorMessage="Your password entries did not match." + Display="Dynamic" />
<com:TTextBox ID="Password2" TextMode="Password" />
Email Address: <com:TRequiredFieldValidator - ControlToValidate="Email" - ErrorMessage="Please provide your email address." - Display="Dynamic" /> + ControlToValidate="Email" + ErrorMessage="Please provide your email address." + Display="Dynamic" /> <com:TEmailAddressValidator - ControlToValidate="Email" - ErrorMessage="You entered an invalid email address." - Display="Dynamic" /> + ControlToValidate="Email" + ErrorMessage="You entered an invalid email address." + Display="Dynamic" />
<com:TTextBox ID="Email" /> @@ -76,8 +76,8 @@ Based on the above analysis, we write the page template as follows: Role:
<com:TDropDownList ID="Role"> - <com:TListItem Text="Normal User" Value="0" /> - <com:TListItem Text="Administrator" Value="1" /> + <com:TListItem Text="Normal User" Value="0" /> + <com:TListItem Text="Administrator" Value="1" /> </com:TDropDownList>
@@ -110,44 +110,44 @@ From the above page template, we see that we need to write a page class that imp class NewUser extends TPage { - /** - * Checks whether the username exists in the database. - * This method responds to the OnServerValidate event of username's custom validator. - * @param mixed event sender - * @param mixed event parameter - */ - public function checkUsername($sender,$param) - { - // valid if the username is not found in the database - $param->IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; - } - - /** - * Creates a new user account if all inputs are valid. - * This method responds to the OnClick event of the "create" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function createButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // populates a UserRecord object with user inputs - $userRecord=new UserRecord; - $userRecord->username=$this->Username->Text; - $userRecord->password=$this->Password->Text; - $userRecord->email=$this->Email->Text; - $userRecord->role=(int)$this->Role->SelectedValue; - $userRecord->first_name=$this->FirstName->Text; - $userRecord->last_name=$this->LastName->Text; - - // saves to the database via Active Record mechanism - $userRecord->save(); - - // redirects the browser to the homepage - $this->Response->redirect($this->Service->constructUrl($this->Service->DefaultPage)); - } - } + /** + * Checks whether the username exists in the database. + * This method responds to the OnServerValidate event of username's custom validator. + * @param mixed event sender + * @param mixed event parameter + */ + public function checkUsername($sender,$param) + { + // valid if the username is not found in the database + $param->IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; + } + + /** + * Creates a new user account if all inputs are valid. + * This method responds to the OnClick event of the "create" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function createButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // populates a UserRecord object with user inputs + $userRecord=new UserRecord; + $userRecord->username=$this->Username->Text; + $userRecord->password=$this->Password->Text; + $userRecord->email=$this->Email->Text; + $userRecord->role=(int)$this->Role->SelectedValue; + $userRecord->first_name=$this->FirstName->Text; + $userRecord->last_name=$this->LastName->Text; + + // saves to the database via Active Record mechanism + $userRecord->save(); + + // redirects the browser to the homepage + $this->Response->redirect($this->Service->constructUrl($this->Service->DefaultPage)); + } + } } -- cgit v1.2.3