IForm

Interface for the Form generator classes. This interface is to insures the class will always be backward compatible.
Source
IForm.php
Implementations
FormBase

Methods

add

void $obj->add(IModel model, array | [string] properties=null)

Add IModel's data properties to the form. You can pass an IModel instance and a list of data properties to be put in the form. The widget for each property is chosen based on the properties definition automatically, thought you can explicitly set a widget to a property in it's definition to the "widget" key.

Arguments

    model (IModel)
    An IModel instance to add it's data properties to the form
    properties=null (array | [string])
    The IModel properties to be added to the model, null=add all properties

Returns

void

add

IForm $obj->add(string label, const type, array atts=null, array params=null)

Add a simple widget (An HTML tag such as an input) to the form.

Arguments

    label (string)
    Row label
    type (const)
    Widget type Form::WIDGET-NAME
    atts=null (array)
    Attributes for the widget HTML tag e.g. {class:my-class,}
    params=null (array)
    Params for the widget

Returns

IForm
For method chaining

addForm

IForm $obj->addForm(
    array | string atts=array,
    string action=null,
    string method='post'
)

Add a form HTML element.

Arguments

    atts=array (array | string)
    string=value of the onsubmit attribute, array=attributes for the form element {attr: value,}
    action=null (string)
    string=URL, null=current URL if "action" is not set in "atts"
    method='post' (string)
    Form submit method can be either 'post', 'get' or 'upload'

Returns

IForm
For method chaining

addSection

IForm $obj->addSection(
    string label='',
    array atts=array,
    const style=FormBase::FIELDSET
)

Add a section. Creates using "fieldset" or "h3" and "div" HTML tags.

Arguments

    label='' (string)
    Section title
    atts=array (array)
    Attributes for the HTML element {attr:value,}
    style=FormBase::FIELDSET (const)
    "FormBase::FIELDSET" or "FormBase::DIVH3"

Returns

IForm
For method chaining

addWidget

IForm $obj->addWidget(string label, string widget, string key=null)

To manually add a row of HTML to the form, opposed to the "add()" method that automatically adds appropriate rows for the give model properties.

Arguments

    label (string)
    Row label
    widget (string)
    Widget HTML to be put in the row
    key=null (string)
    A unique key across form rows, this key will be used in the if/name attribute values of tags related to the form row

Returns

IForm
For method chaining

attributes

IForm $obj->attributes(array atts=null)

To manually set HTML attributes for form elements.

Arguments

    atts=null (array)
    You can address the form HTML elements to assign attributes as shown below: [@FormBase.attributes.atts]

Returns

IForm
For method chaining

closeForm

IForm $obj->closeForm()

Close opened form element. The last opened form will be closed automatically without the need to use this method.

Returns

IForm
For method chaining

closeSection

object $obj->closeSection()

Close an opened section element. The last opened form will be closed automatically without the need to use this method.

Returns

object
this - for method chaining

params

IForm $obj->params(array params=null)

Set form widget parameters with this method. Note that for instances of the "IModel" the best fitting parameters are chosen automatically, however parameters to override the default configs may be set using this method.

Arguments

    params=null (array)
    You can set parameters for the model data properties as: [@FormBase.params.params]

Returns

IForm
For method chaining

raw

array $obj->raw()

Returns an array of form rows and data about rendering the form. Use this method instead of "IForm.render()" when you want to manually render the form.

Returns

array
{row-or-property-name: {render-data},}

render

string $obj->render(const layout=Form::FORM_LABEL_LAYOUT_H)

Render the form as HTML.

Arguments

    layout=Form::FORM_LABEL_LAYOUT_H (const)
    Form row layout can be "Form::FORM_LABEL_LAYOUT_H" or "Form::FORM_LABEL_LAYOUT_V"

Returns

string
HTML

reset

IForm $obj->reset(string formName=null)

To reset all configs to default, this can be useful when creating multiple forms with the same "IForm" object.

Arguments

    formName=null (string)
    This value will be added to all HTML id attributes related to the form e.g. id="AAA-formName"

Returns

IForm
For method chaining