Skip to content

Instantly share code, notes, and snippets.

@chrisdpeters
Created February 16, 2012 22:49
Show Gist options
  • Save chrisdpeters/1848500 to your computer and use it in GitHub Desktop.
Save chrisdpeters/1848500 to your computer and use it in GitHub Desktop.
Script-Based Controllers and Models, Tag-Based Views
component extends="Controller" {
/**
@hint Shows form for registering for social network.
*/
public function register() {
user = model("user").new();
}
/**
@hint Saves registration submission.
*/
public function create() {
user = model("user").new(params.user);
user.save();
if(user.hasErrors()) {
renderPage(action="register");
}
else {
flashInsert(success="Thank you for registering for Social Network.");
redirectTo(controller="home");
}
}
}
component extends="Model" {
/**
@hint Initializes associations and validations
*/
public function init() {
// Associations
hasMany("chirps");
// Validations
validatesPresenceOf("firstName,lastName,email,gender,urlId");
validatesUniquenessOf("email,urlId");
validatesLengthOf(properties="firstName,lastName", maximum=50);
}
}
<cfparam name="user">
<cfoutput>
<h1>Register for Social Network</h1>
#startFormTag(action="create")#
#textField(label="First Name", objectName="user", property="firstName")#
#textField(label="Last Name", objectName="user", property="lastName")#
#textField(label="Email", objectName="user", property="email")#
<fieldset>
<legend>Gender</legend>
#radioButton(label="Male", objectName="user", property="gender", tagValue="M")#
#radioButton(label="Female", objectName="user", property="gender", tagValue="F")#
</fieldset>
<fieldset>
<legend>Profile Address</legend>
#textField(label="http://#cgi.script_name#/profile/", objectName="user", property="urlId")#
</fieldset>
<div>
#submitTag(value="Register Now")#
</div>
#endFormTag()#
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment