diff options
author | wei <> | 2007-05-10 23:00:04 +0000 |
---|---|---|
committer | wei <> | 2007-05-10 23:00:04 +0000 |
commit | e2cb0b52aaa02a3f3f41d0df377d189529713738 (patch) | |
tree | ee4c2a3fece40c9a2d4dde75f6e758f7ef05f8f6 /demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page | |
parent | ef2fc3942664d4d7131542080e838f7754a3081f (diff) |
Update blog tutorial
Diffstat (limited to 'demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page')
-rw-r--r-- | demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page | 120 |
1 files changed, 60 insertions, 60 deletions
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: <span>Username:</span>
<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" />
<br/>
<com:TTextBox ID="Username" />
<br/>
<span>Password:</span>
<com:TRequiredFieldValidator
- ControlToValidate="Password"
- ErrorMessage="Please provide a password."
- Display="Dynamic" />
+ ControlToValidate="Password"
+ ErrorMessage="Please provide a password."
+ Display="Dynamic" />
<br/>
<com:TTextBox ID="Password" TextMode="Password" />
<br/>
<span>Re-type Password:</span>
<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" />
<br/>
<com:TTextBox ID="Password2" TextMode="Password" />
<br/>
<span>Email Address:</span>
<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" />
<br/>
<com:TTextBox ID="Email" />
@@ -76,8 +76,8 @@ Based on the above analysis, we write the page template as follows: <span>Role:</span>
<br/>
<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>
<br/>
@@ -110,44 +110,44 @@ From the above page template, we see that we need to write a page class that imp <com:TTextHighlighter CssClass="source" Language="php">
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));
+ }
+ }
}
</com:TTextHighlighter>
|