<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># NAME

HTML::Shakan - Form HTML generator/validator

# SYNOPSIS

    use HTML::Shakan;

    sub form {
        my $req = shift;
        HTML::Shakan-&gt;new(
            fields =&gt; [ @_ ],
            request =&gt; $req,
            model =&gt; 'DataModel',
        );
    }
    sub edit {
        my $req = shift;
        my $row = $model-&gt;get('user' =&gt; $req-&gt;param('id'));
        my $form = form(
            $req =&gt; (
                TextField(name =&gt; 'name', label =&gt; 'Your name', filter =&gt; [qw/WhiteSpace/]),
                EmailField(name =&gt; 'email', label =&gt; 'Your email'),
            ),
        );
        if ($req-&gt;submitted_and_valid) {
            $form-&gt;model-&gt;update($row);
            redirect('edit_thanks');
        } else {
            $form-&gt;model-&gt;fill($row);
            render(form =&gt; $form);
        }
    }
    sub add {
        my $req = shift;
        my $form = form(
            $req =&gt; (
                TextField(name =&gt; 'name', label =&gt; 'Your name'),
                EmailField(name =&gt; 'email', label =&gt; 'Your email'),
            )
        );
        if ($req-&gt;submitted_and_valid) {
            $form-&gt;model-&gt;insert($model =&gt; 'user');
            redirect('edit_thanks');
        }
        render(form =&gt; $form);
    }

    # in your template
    &lt;? if ($form-&gt;has_error) { ?&gt;&lt;div class="error"&gt;&lt;?= $form-&gt;error_message() ?&gt;&lt;/div&gt;&lt;? } ?&gt;
    &lt;form method="post" action="add"&gt;
    &lt;?= $form-&gt;render() ?&gt;
    &lt;p&gt;&lt;input type="submit" value="add" /&gt;&lt;/p&gt;
    &lt;/form&gt;

# DESCRIPTION

HTML::Shakan is yet another form generator.

THIS IS BETA.API WILL CHANGE.

# ATTRIBUTES

- custom\_validation

        form 'login' =&gt; (
            fields =&gt; [
                TextField(name =&gt; 'login_id'),
                PasswordField(name =&gt; 'login_pw'),
            ],
            custom_validation =&gt; sub {
                my $form = shift;
                if ($form-&gt;is_valid &amp;&amp; !MyDB-&gt;retrieve($form-&gt;param('login_id'), $form-&gt;param('login_pw'))) {
                    $form-&gt;set_error('login' =&gt; 'failed');
                }
            }
        );

    You can set custom validation callback, validates the field set in the form. For example, this is useful for login form.

- submitted

    Returns true if the form has been submitted.

    This attribute will return true if a value for any known field name was submitted.

- has\_error

    Return true if request has an error.

- submitted\_and\_valid

    Shorthand for `$form-&gt;submitted &amp;&amp; !$form-&gt;has_error`

# benchmarking

form generation

                     Rate         formfu         shakan shakan_declare
    formfu         1057/s             --           -77%           -84%
    shakan         4695/s           344%             --           -31%
    shakan_declare 6757/s           539%            44%             --

# What's shakan

Shakan is ĺ·¦ĺ® in Japanese.

If you want to know about shakan, please see [http://www.konuma-sakan.com/index2.html](http://www.konuma-sakan.com/index2.html)

ĺ·¦ĺ® should pronounce 'sakan', formally. but, edokko pronounce ĺ·¦ĺ® as shakan.

# METHODS

- `my $html = $shakan-&gt;render(); :Str`

    Render form.

- `$shakan-&gt;render_field($name); :Str`

    Render partial form named `&lt;$name`\&gt;.

# AUTHOR

Tokuhiro Matsuno &lt;tokuhirom  @ gmail.com&gt;

# SEE ALSO

[HTML::FormFu](http://search.cpan.org/perldoc?HTML::FormFu)

ToscaWidgets

# LICENSE

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
</pre></body></html>