User:OliverCharles/ServerManual/Forms

From MusicBrainz Wiki
< User:OliverCharles‎ | ServerManual
Revision as of 11:29, 15 April 2009 by OliverCharles (talk | contribs) (Starting work on #4756)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Forms are created in 3 separate parts - designing the form at the data level, designing a view to the form, and adding controller logic to work with the form.

Writing Form Modules

Form modules are handled by writing Form::Processor modules, in the MusicBrainz::Server::Form namespace. You should add a new level of hierarchy to match the name of your controller (for example, MusicBrainz::Server::Form::Annotation::Edit).

Rather than inheriting directly from Form::Processor, it is best to inherit from MusicBrainz::Server::Form - this module exports some small helper methods to create common fields such as edit notes, and may do more in the future.

The single most important method in a form module is profile. This is the skeleton for a template, and will create all relevant fields. Your profile method should return a hash reference, with fields under the required and optional keys.

sub profile
{
    return {
        required => {
            <name> => <type>,
        },
        optional => {
            <name> => <type>,
        },
    }
}

Rather than documenting the details of how profile work here, you should read the official documentation.

Advanced

Reference

Field Types

MusicBrainz::Server::Form