NAME

StateMachine::Gestinanna::Examples::MailForm - example mail form state machine

SYNOPSIS

package My::MailForm;

use base qw/StateMachine::Gestinanna::Examples::MailForm/;

our %EDGES = (
    showform => {
        submitform => {
            required => [qw(
                name
                message
            )],
            overrides => {
                smtp_host => 'localhost',
                mail_to => 'me@localhost',
                env_fields => [qw(REMOTE_HOST)],
                mail_from => 'you@localhost',
            },
        },
    },
);

1;
__END__

In an HTML::Mason component (for example):

<%once>
    use My::MailForm;
</%once>
<%init>
    # assume session info is set up for us

    # instantiate & initialize state machine object
    my $sm = My::MailForm -> new($session -> {context});

    # go to next state
    $sm -> process(%ARGS);

    my $view = $sm -> state;
    my $viewdata = {
         in    => $sm -> data('in'),
         out   => $sm -> data('out'),
         error => $sm -> data('error'),
    },

    # save for next go-around
    $session -> {context} = $sm -> context;
</%init>
%# possible states: showform, submitform, error
<& "views/$view", %$viewdata &>

DESCRIPTION

This example state machine reproduces much of the example CGI::Application::Mailform. Instead of initializing the object with parameters, however, you may make them part of the state machine definition as overrides. This has the added benefit of allowing any or all of them to be specified in the form being submitted.

Any information submitted in the form that is not one of the four variables (env_fields, mail_from, mail_to, and smtp_host) and is allowed by the validation will be sent to the mail_to address as an email. In addition, any environment variables listed in env_fields will also be sent.

The four variables mentioned above are required for the state machine to transit to the submitform state (actually, env_fields and smtp_host are optional). The mail_to and mail_from variables must appear to be e-mail addresses.

E-mail is only sent if the smtp_host is available and the transition is made to the submitform state from the showform state. Once the transition is finished (and the process method has returned), the e-mail has been sent or an error has been reported.

SEE ALSO

CGI::Application::Mailform, StateMachine::Gestinanna.

AUTHOR

James G. Smith <jsmith@cpan.org>

COPYRIGHT

Copyright (C) 2002-2004 Texas A&M University. All Rights Reserved.

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