NAME

Waft - A simple web application framework

SYNOPSIS

    ==========================================================================
    myform.cgi
    --------------------------------------------------------------------------
    #!/usr/bin/perl
    use lib 'lib';
    require MyForm;
    MyForm->waft;

    ==========================================================================
    lib/MyForm.pm
    --------------------------------------------------------------------------
    package MyForm;

    use base 'Waft';

    sub __default__direct {
        my ($self) = @_;

        $self->{name} = q{};
        $self->{address} = q{};
        $self->{phone} = q{};
        $self->{comment} = q{};

        return 'TEMPLATE';
    }

    sub __default__submit {
        my ($self) = @_;

        $self->{name} = $self->query->param('name');
        $self->{address} = $self->query->param('address');
        $self->{phone} = $self->query->param('phone');
        $self->{comment} = $self->query->param('comment');

        return 'confirm.html';
    }

    sub __confirm__indirect {
        my ($self) = @_;

        return 'default.html', 'error!' if length $self->{name} == 0;

        return 'TEMPLATE';
    }

    sub __confirm__submit {
        return 'thankyou.html';
    }

    sub __confirm__back {
        return 'default.html';
    }

    sub __thankyou__indirect {
        my ($self) = @_;

        open my $fh, '>> form.log';
        print {$fh} $self->{name}, "\n";
        print {$fh} $self->{address}, "\n";
        print {$fh} $self->{phone}, "\n";
        print {$fh} $self->{comment}, "\n";
        close $fh;

        return 'TEMPLATE';
    }

    1;

    ==========================================================================
    lib/MyForm.template/default.html
    --------------------------------------------------------------------------
    <%
    my ($self, $error) = @_;
    %>
    <html>

    <head>
        <title>FORM</title>
    </head>

    <body>
        <% if ($error) { %>
            <p>
            <% = $error %>
            </p>
        <% } %>

        <form action="<% = $self->url %>" method="POST">

        <p>
        Name:
        <input type="text" name="name" value="<% = $self->{name} %>" />
        </p>

        <p>
        Address:
        <input type="text" name="address" value="<% = $self->{address} %>" />
        </p>

        <p>
        Phone:
        <input type="text" name="phone" value="<% = $self->{phone} %>" />
        </p>

        <p>
        Comment: <br />
        <textarea name="comment"><% = $self->{comment} %></textarea>
        </p>

        <p>
        <input type="submit" />
        </p>

        </form>
    </body>

    </html>

    ==========================================================================
    lib/MyForm.template/confirm.html
    --------------------------------------------------------------------------
    <%
    my ($self) = @_;
    %>
    <html>

    <head>
        <title>FORM - CONFIRM</title>
    </head>

    <body>
        <form action="<% = $self->url %>" method="POST">

        <p>
        Name: <% = $self->{name} %>
        </p>

        <p>
        Address: <% = $self->{address} %>
        </p>

        <p>
        Phone: <% = $self->{phone} %>
        </p>

        <p>
        Comment: <br />
        <% text = $self->{comment} %>
        </p>

        <p>
        <input type="submit" />
        <input type="submit" name="back" value="back to FORM" />
        </p>

        </form>
    </body>

    </html>

    ==========================================================================
    lib/MyForm.template/thankyou.html
    --------------------------------------------------------------------------
    <%
    my ($self) = @_;
    %>
    <html>

    <head>
        <title>FORM - THANKYOU</title>
    </head>

    <body>
        <p>
        Thank you for your comment!
        </p>

        <p>
        Name: <% = $self->{name} %>
        </p>

        <p>
        Address: <% = $self->{address} %>
        </p>

        <p>
        Phone: <% = $self->{phone} %>
        </p>

        <p>
        Comment: <br />
        <% text = $self->{comment} %>
        </p>
    </body>

    </html>

AUTHOR

Yuji Tamashiro, <yuji@tamashiro.org>

COPYRIGHT AND LICENSE

Copyright (C) 2007 by Yuji Tamashiro

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