Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The ModuleFields class is automatically made available to any module. To being begin using it simply initialize the object within your module method.

...

  • getPackageFields
  • getAdminAddFields
  • getClientAddFields
  • getAdminEditFields
  • getClientEditFields

Creating Fields

...

Creating fields using the ModuleFields class allows you to define a set of input fields that may be displayed in a variety of context, without worrying about how those fields are contained. There are three aspects of creating a field, described below, that including: creating the field label, creating the field, and attaching the field to the label.

Creating Labels

Creating a label will return a ModuleField object.

Code Block
languagephp
title/components/modules/my_module/my_module.php
<?php 
class MyModule extends Module { 
    
    ... 

    public function getPackageFields($vars=null) {
        // Create the label
        $fields = new ModuleFields();
        $my_label = $fields->label("My Field Label", "my_field_label_id");

        $fields->setField($my_label);
        return $fields;
    }
}
?>

Creating Fields

As with creating a label, creating a field will return a ModuleField object.

Code Block
languagephp
title/components/modules/my_module/my_module.php
<?php 
class MyModule extends Module { 

    ...

    public function getPackageFields($vars=null) {
        // Create the label
        $fields = new ModuleFields();
        $my_label = $fields->label("My Field Label", "my_field_id");
        
        // Create the field
        $my_field = $fields->fieldText("my_field_name", array('id' => "my_field_id"));
 
        $fields->setField($my_label);
        return $fields;
    }
}
?>

Attaching a Label to a Field

Now that we've seen how to create an input label and field, let's attach them together

Code Block
languagephp
title/components/modules/my_module/my_module.php
<?php 
class MyModule extends Module { 

    ...

    public function getPackageFields($vars=null) {
        // Create the label
        $fields = new ModuleFields();
        $my_label = $fields->label("My Field Label", "my_field_id");
        
        // Create the field
        $my_field = $fields->fieldText("my_field_name", array('id' => "my_field_id"));

        // Attach the field to the label
        $my_label->attach($my_field);

        $fields->setField($my_label);
        return $fields;
    }
}
?>

Creating HTML content

The ModuleFields class supports HTML content as well. You may choose to set nothing but HTML content, but the best practice is to set fields using the method mentioned in the section above and only set javascript and that sort of thing as HTML content.

...

Code Block
languagephp
title/components/modules/my_module/my_module.php
<?php
class MyModule extends Module {

    ...

    public function getPackageFields($vars=null) {
        $fields = new ModuleFields();
        $fields->setHtml("
            <script type=\"text/javascript\">alert('ok!');</script>
        ");

    }
}
?>