| HTML-Shakan documentation | view source | Contained in the HTML-Shakan distribution. |
HTML::Shakan - form html generator/validator
use HTML::Shakan;
sub form {
my $req = shift;
HTML::Shakan->new(
fields => [ @_ ],
request => $req,
model => 'DataModel',
);
}
sub edit {
my $req = shift;
my $row = $model->get('user' => $req->param('id'));
my $form = form(
$req => (
TextField(name => 'name', label => 'Your name', filter => [qw/WhiteSpace/]),
EmailField(name => 'email', label => 'Your email'),
),
);
if ($req->submitted_and_valid) {
$form->model->update($row);
redirect('edit_thanks');
} else {
$form->model->fill($row);
render(form => $form);
}
}
sub add {
my $req = shift;
my $form = form(
$req => (
TextField(name => 'name', label => 'Your name'),
EmailField(name => 'email', label => 'Your email'),
)
);
if ($req->submitted_and_valid) {
$form->model->insert($model => 'user');
redirect('edit_thanks');
}
render(form => $form);
}
# in your template
<? if ($form->has_error) { ?><div class="error"><?= $form->error_message() ?></div><? } ?>
<form method="post" action="add">
<?= $form->render() ?>
<p><input type="submit" value="add" /></p>
</form>
HTML::Shakan is yet another form generator.
THIS IS BETA.API WILL CHANGE.
form 'login' => (
fields => [
TextField(name => 'login_id'),
PasswordField(name => 'login_pw'),
],
custom_validation => sub {
my $form = shift;
if ($form->is_valid && !MyDB->retrieve($form->param('login_id'), $form->param('login_pw'))) {
$form->set_error('login' => 'failed');
}
}
);
You can set custom validation callback, validates the field set in the form. For example, this is useful for login form.
Returns true if the form has been submitted.
This attribute will return true if a value for any known field name was submitted.
Return true if request has an error.
Shorthand for $form->submitted && !$form->has_error
form generation
Rate formfu shakan shakan_declare
formfu 1057/s -- -77% -84%
shakan 4695/s 344% -- -31%
shakan_declare 6757/s 539% 44% --
Shakan is 左官 in Japanese.
If you want to know about shakan, please see http://www.konuma-sakan.com/index2.html
左官 should pronounce 'sakan', formally. but, edokko pronounce 左官 as shakan.
Render form.
Render partial form named <$name>.
Tokuhiro Matsuno <tokuhirom slkjfd gmail.com>
ToscaWidgets
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| HTML-Shakan documentation | view source | Contained in the HTML-Shakan distribution. |