summaryrefslogtreecommitdiff
path: root/demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page
diff options
context:
space:
mode:
Diffstat (limited to 'demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page')
-rw-r--r--demos/blog-tutorial/protected/pages/Day3/CreateNewUser.page120
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>
&lt;com:TRequiredFieldValidator
- ControlToValidate="Username"
- ErrorMessage="Please provide a username."
- Display="Dynamic" />
+ ControlToValidate="Username"
+ ErrorMessage="Please provide a username."
+ Display="Dynamic" />
&lt;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/>
&lt;com:TTextBox ID="Username" />
<br/>
<span>Password:</span>
&lt;com:TRequiredFieldValidator
- ControlToValidate="Password"
- ErrorMessage="Please provide a password."
- Display="Dynamic" />
+ ControlToValidate="Password"
+ ErrorMessage="Please provide a password."
+ Display="Dynamic" />
<br/>
&lt;com:TTextBox ID="Password" TextMode="Password" />
<br/>
<span>Re-type Password:</span>
&lt;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/>
&lt;com:TTextBox ID="Password2" TextMode="Password" />
<br/>
<span>Email Address:</span>
&lt;com:TRequiredFieldValidator
- ControlToValidate="Email"
- ErrorMessage="Please provide your email address."
- Display="Dynamic" />
+ ControlToValidate="Email"
+ ErrorMessage="Please provide your email address."
+ Display="Dynamic" />
&lt;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/>
&lt;com:TTextBox ID="Email" />
@@ -76,8 +76,8 @@ Based on the above analysis, we write the page template as follows:
<span>Role:</span>
<br/>
&lt;com:TDropDownList ID="Role">
- &lt;com:TListItem Text="Normal User" Value="0" />
- &lt;com:TListItem Text="Administrator" Value="1" />
+ &lt;com:TListItem Text="Normal User" Value="0" />
+ &lt;com:TListItem Text="Administrator" Value="1" />
&lt;/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>