Jump to content

Developer Documentation

Displaying a form

Outputting the form

Casting the $form object to a string returns the HTML to display the form. You don't usually need to cast the form explicitly, simply adding it to the output buffer (e.g. \IPS\Output::i()->output) will be fine. e.g.

\IPS\Output::i()->output .= $form;

 

Adding custom CSS to a form

By default, the form is "horizontal". To use "vertical", or to apply any other classes to the form, you can do:

$form->class = 'ipsForm_vertical';

The class property is a simple string (not an array), so simply use a space-separated list of CSS classnames.

If you use your own CSS styles rather than built-in classnames, don't forget to include your CSS file too!

 

Using custom form templates

By default, standard built-in form templates are used when displaying a form. For further customization though, you can call $form->customTemplate() passing a callback with a template to use. This allows you to totally customize the look of the form.

A common use of this is to use a template that looks better in modals:

\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );

The template you create must contain the following template header, including these parameters:

<ips:template parameters="$id, $action, $elements, $hiddenValues, $actionButtons, $uploadField, $class='', $attributes=array(), $sidebar, $form=NULL" />

 

Passing custom parameters

If you need to pass additional custom parameters to your form template, you can do that in the second parameter of the customTemplate method, like so:

$templateToUse = array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' );
$form->customTemplate( $templateToUse, $myCustomParameter, $anotherParameter );

Your parameters are added to the front of the template parameter list, meaning in this case, your template header would be:

<ips:template parameters="$myCustomParameter, $anotherParameter, $id, $action, $elements, $hiddenValues, $actionButtons, $uploadField, $class='', $attributes=array(), $sidebar, $form=NULL" />

 


  Report Document


×
×
  • Create New...