Function: checkbox()

function checkbox(array $parameters, bool $echo = true): string|null;

Function for rendering the checkbox field.

Details

This function renders a checkbox field that is bound to the request variable with the corresponding name.

Parameters

Name Pass type Value type Default value Description
$parameters by value array

The array of parameters as an associative array in the form key => value:

  • $parameters["id"] - id of the field.

  • $parameters["name"] - name of the field.

  • $parameters["value"] - the value of the request variable that should be submitted if the checkbox is checked.

  • $parameters["checked"] - checked state that should be set for the field. If it is not specified, the value of the corresponding request variable is used to set the checked state.

Any other attributes may be specified.

Example:

checkbox(["id" => "data_checkbox",
          "name" => "data[checkbox]",
          "class" => "my_class",
          "value" => "1",
          "title" => "select checkbox",
          "data-prop" => "some-prop"
         ]);
$echo by value bool true

If the value of $echo is true, the html code of the field is directly echoed. Otherwise it is returned as string. It might be useful to pass this code to other rendering functions instead of echoing.

Returns

string|null

If the paramter $echo is true, the string of the field html code is returned, otherwise null.

Authors

Oleg Schildt

Package

Source code

See also