Skip to content

Instantly share code, notes, and snippets.

@woosley
Created July 3, 2011 00:54
Show Gist options
  • Save woosley/1061847 to your computer and use it in GitHub Desktop.
Save woosley/1061847 to your computer and use it in GitHub Desktop.
html formhandler form definition
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