array_to_form() form()

Build the fields from an array of [method, name, desc or options, ...] rows, e.g. a form kept in a config file.

form()->array_to_form($a = [], $params = [], $replace = [])

Options

OptionMeaning
$aRows: 'save' or ['text', 'login', ['class' => 'input-medium']]; unknown methods are skipped.
$params, $replaceMerged into the form options and values.

Example

Code

$fields = [
    ['text', 'login', 'Login'],
    ['email', 'email'],
    ['select_box', 'role', ['user' => 'User', 'editor' => 'Editor']],
    'save',
];
return form(['login' => 'anna', 'role' => 'editor'])->array_to_form($fields);

Notes

  • Each row calls $method($row[1], $row[2], $row[3], ...): the arguments follow the method signature.
  • The method names must come from site code, never from request data.

See also: form/tpl_row, form/form