User:OliverCharles/ServerManual/Forms: Difference between revisions

From MusicBrainz Wiki
Jump to navigationJump to search
(Starting work on #4756)
 
(Document with_mod_fields)
Line 24: Line 24:


Rather than documenting the details of how profile work here, you should read the [http://search.cpan.org/~hank/Form-Processor-0.19/lib/Form/Processor.pm#METHODS official documentation].
Rather than documenting the details of how profile work here, you should read the [http://search.cpan.org/~hank/Form-Processor-0.19/lib/Form/Processor.pm#METHODS official documentation].

==For Forms That Enter Edits==

If your form creates an edit, you should wrap the result of profile with a call to <tt>with_mod_fields</tt>. This will create fields for an edit note, and a toggle to change auto-editor status.

<pre>
sub profile
{
return shift->with_mod_fields({
})
}
</pre>


=Advanced=
=Advanced=

==Composite Fields==

Composite fields are fields that require multiple inputs to create a value. Examples of these are the date input fields (which split into YYYY-MM-DD), and track fields. For the most part, you can create your own composite fields


=Reference=
=Reference=

==Field Types==
==Field Types==

==MusicBrainz::Server::Form==
==MusicBrainz::Server::Form==

===with_mod_fields===

Add fields for an edit note, and the ability to toggle auto-editor status.

Revision as of 11:32, 15 April 2009

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.

For Forms That Enter Edits

If your form creates an edit, you should wrap the result of profile with a call to with_mod_fields. This will create fields for an edit note, and a toggle to change auto-editor status.

sub profile
{
    return shift->with_mod_fields({
        …
    })
}

Advanced

Composite Fields

Composite fields are fields that require multiple inputs to create a value. Examples of these are the date input fields (which split into YYYY-MM-DD), and track fields. For the most part, you can create your own composite fields

Reference

Field Types

MusicBrainz::Server::Form

with_mod_fields

Add fields for an edit note, and the ability to toggle auto-editor status.