Forms

Elgg defines some standard views for form elements and variable display.

It is highly recommended to use these views when constructing plugin and displaying form data inside your plugins. Not does it mean that your plugin can seamlessly take advantage of extra functionality defined by other plugins (such as a rich text editor), but it also helps protect you from certain exploits.

Contents

Form view

All input fields are encapsulated inside an input/form view. This view accepts the following parameters in its $vars array:

  • $vars['body'] The body of the form (made up of other input/xxx views and html
  • $vars['method'] Method (default POST)
  • $vars['enctype'] How the form is encoded, default blank
  • $vars['action'] URL of the action being called, e.g. "{$CONFIG->url}actions/my/action"
  • $vars['internalname'] Name field - mainly used for CSS/JS
  • $vars['internalid'] ID field - mainly used for CSS/JS

Example form

$form_body = "<p>This is my form</p>";
$form_body .= elgg_view('input/text', array('internalname' => 'mytextbox', 'value' => 'Initial value'));
$form_body .= elgg_view('input/submit', array('internalname' => 'submit'));
 
echo elgg_view('input/form', array('body' => $form_body, 'action' => "{$CONFIG->url}actions/my/action"));

Input views

Input views provide a safe and extendible way of representing data input fields, they all live in "input/xxxxxx".

Output views

Output views are the companion to input views and govern the display of input fields such as text, longtext, urls etc.

They all live in "output/xxxxxx".

Search docs