Created
July 3, 2011 00:54
-
-
Save woosley/1061847 to your computer and use it in GitHub Desktop.
html formhandler form definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package SEA::Forms::User; | |
use HTML::FormHandler::Moose; | |
extends 'HTML::FormHandler::Model::DBIC'; | |
use namespace::autoclean; | |
use Digest::MD5 qw/md5_hex/; | |
has '+name' => (default => 'user'); | |
has '+auto_fieldset' => (default => 0); | |
has '+item_class' => (default => 'User'); | |
has '+dependency' => (default => sub { [[qw/password confirm/]] }); | |
has_field 'id' => ( | |
type => 'Text', | |
required => 1, | |
accessor => 'username', | |
unique => 1, | |
apply => [ | |
{ check => qr/^\w{7}$/, | |
message => 'Invalid username' | |
} | |
], | |
messages => { | |
required => 'username is required', | |
unique => 'This username is already taken' | |
}, | |
); | |
has_field 'email' => ( | |
unique => 1, | |
messages => {unique => 'This email is already taken'}, | |
apply => [ | |
{ check => qr/^\w+\.\w+\@ericsson\.com$/, | |
message => 'Invalid Email' | |
} | |
], | |
); | |
has_field 'password' => ( | |
type => 'Password', | |
accessor => 'password', | |
apply => [ | |
{ transform => sub { md5_hex(shift) } | |
} | |
], | |
); | |
has_field 'confirm' => ( | |
type => 'Password', | |
apply => [ | |
{ transform => sub { md5_hex(shift) } | |
} | |
], | |
); | |
has_field 'submit' => ( | |
value => 'submit', | |
type => 'Submit', | |
css_class => 'submit' | |
); | |
sub validate { | |
my ($self) = @_; | |
if ($self->field('confirm')->value ne $self->field('password')->value) { | |
$self->field('password')->add_error("password not match"); | |
} | |
} | |
__PACKAGE__->meta->make_immutable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment