Menu

## Form extends KBase
in package

Form.php : 18

Form class

##### Tags

see
  https://www.kotchasan.com/

### Table of Contents

$ajax : bool
  Variable to indicate whether Ajax form is being used or not.
$gform : bool
  Variable to indicate whether the form is being used with GForm or not.
$javascript : array<string|int, mixed>
  JavaScript
$cfg : object
  Config class instance.
$request : Request
  Server request class instance.
$attributes : array<string|int, mixed>
  Tag attributes
$tag : string
  Tag name
button() : static
  Create a button element.
checkbox() : static
  Create an input element of type "checkbox".
color() : static
  Create an input element of type "color".
currency() : static
  Create an input element for handling currency values.
date() : static
  Create an input element of type "date".
datetime() : static
  Create an input element of type "datetime".
email() : static
  Create an input element of type "email".
file() : static
  Create an input element of type "file".
get2Input() : array<string|int, mixed>
  Retrieve input values from query parameters and parsed body.
hidden() : static
  Create an input element of type "hidden".
integer() : static
  Create an input element of type "integer" that allows negative values.
number() : static
  Create an input element of type "number".
password() : static
  Create an input element of type "password".
radio() : static
  Create an input element of type "radio".
range() : static
  Create an input element of type "range".
render() : string
  Function for generating form elements.
reset() : static
  Creates a reset button element.
select() : static
  Creates a select dropdown element.
submit() : static
  Creates a submit button or input field.
tel() : static
  Create an input element of type "tel".
text() : static
  Create an input element of type "text".
textarea() : static
  Create an input element of type "textarea".
time() : static
  Create an input element of type "time".
url() : static
  Create an input element of type "url".
create() : string
  Creates an HTML element with the specified attributes and inner HTML.

### Properties

#### $ajax

Form.php : 26

Variable to indicate whether Ajax form is being used or not.

`public bool $ajax = false`

GAjax must be called if this is set to true.

#### $gform

Form.php : 34

Variable to indicate whether the form is being used with GForm or not.

`public bool $gform = true`

GAjax must be called if this is set to true.

#### $javascript

Form.php : 41

JavaScript

`public array<string|int, mixed> $javascript`

#### $cfg

KBase.php : 26

Config class instance.

`protected static object $cfg`

#### $request

KBase.php : 33

Server request class instance.

`protected static Request $request`

#### $attributes

Form.php : 48

Tag attributes

`private array<string|int, mixed> $attributes`

#### $tag

Form.php : 55

Tag name

`private string $tag`

### Methods

#### button()

Form.php : 68

Create a button element.

`public static button([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 'Test', 'disabled' => true))->render() [==] '
  '

assert

  (array('id' => 'test_id', 'value' => 'Test', 'disabled' => true, 'tag' => 'input'))->render() [==] ''

##### Return values

static —

#### checkbox()

Form.php : 95

Create an input element of type "checkbox".

`public static checkbox([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1))->render() [==] ''

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test'))->render() [==] 'Test'

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test', 'itemClass' => 'item'))->render() [==] '

  Test
  '
assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-valid'))->render() [==] '

  Test
  '

##### Return values

static —

#### color()

Form.php : 115

Create an input element of type "color".

`public static color([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => '#FFF', 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => '#FFF', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-color'))->render() [==] '

  Test
  '

##### Return values

static —

#### currency()

Form.php : 136

Create an input element for handling currency values.

`public static currency([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => 100, 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-money'))->render() [==] '

  Test
  '

##### Return values

static —

#### date()

Form.php : 157

Create an input element of type "date".

`public static date([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => '#FFF', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-calendar'))->render() [==] '

  Test
  '

##### Return values

static —

#### datetime()

Form.php : 177

Create an input element of type "datetime".

`public static datetime([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => '2021-01-01 12:00', 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => '2021-01-01 12:00', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-calendar'))->render() [==] '

  Test
  '

##### Return values

static —

#### email()

Form.php : 197

Create an input element of type "email".

`public static email([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-email'))->render() [==] '

  Test
  '

##### Return values

static —

#### file()

Form.php : 217

Create an input element of type "file".

`public static file([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-file'))->render() [==] '

  Test
  '

##### Return values

static —

#### get2Input()

Form.php : 232

Retrieve input values from query parameters and parsed body.

`public static get2Input() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

An array of hidden input elements.

#### hidden()

Form.php : 265

Create an input element of type "hidden".

`public static hidden([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1))->render() [==] ''

##### Return values

static —

#### integer()

Form.php : 305

Create an input element of type "integer" that allows negative values.

`public static integer([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => -100, 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-number'))->render() [==] '

  Test
  '

##### Return values

static —

#### number()

Form.php : 285

Create an input element of type "number".

`public static number([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => 1234, 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-number'))->render() [==] '

  Test
  '

##### Return values

static —

#### password()

Form.php : 325

Create an input element of type "password".

`public static password([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => '1234', 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => '1234', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-color'))->render() [==] '

  Test
  '

##### Return values

static —

#### radio()

Form.php : 347

Create an input element of type "radio".

`public static radio([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1))->render() [==] ''

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test'))->render() [==] 'Test'

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test', 'itemClass' => 'item'))->render() [==] '

  Test
  '
assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-valid'))->render() [==] '

  Test
  '

##### Return values

static —

#### range()

Form.php : 367

Create an input element of type "range".

`public static range([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test', 'itemClass' => 'item'))->render() [==] '

  Test
  '

##### Return values

static —

#### render()

Form.php : 395

Function for generating form elements.

`public render() : string`

The function supports the following parameters:

- id, name, type: properties of the input element.
- options: for select elements only, an array of options in the format array('value1' => 'name1', 'value2' => 'name2', ...).
- datalist: for text input elements, an array of options in the format array('value1' => 'name1', 'value2' => 'name2', ...).
- label: the label text to display for the input element.
- labelClass: the CSS class of the label.
- comment: if specified, displays a description of the input.

If neither label nor labelClass is specified, only the input element will be created.

##### Return values

string —

The generated HTML for the form element.

#### reset()

Form.php : 693

Creates a reset button element.

`public static reset([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 'Test', 'disabled' => true))->render() [==] '
  '

assert

  (array('id' => 'test_id', 'value' => 'Test', 'disabled' => true, 'tag' => 'input'))->render() [==] ''

##### Return values

static —

#### select()

Form.php : 724

Creates a select dropdown element.

`public static select([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test', 'options' => [0 => 0, 1 => 1]))->render() [==] 'Test
  '

assert

  (array('id' => 'test_id', 'value' => '#FFF', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-color', 'options' => [0 => 0, 1 => 1]))->render() [==] '

  Test
  '

##### Return values

static —

#### submit()

Form.php : 743

Creates a submit button or input field.

`public static submit([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 'Test', 'disabled' => true))->render() [==] '
  '

assert

  (array('id' => 'test_id', 'value' => 'Test', 'disabled' => true, 'tag' => 'input'))->render() [==] ''

##### Return values

static —

#### tel()

Form.php : 774

Create an input element of type "tel".

`public static tel([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => '0123456789', 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => '0123456789', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-phone'))->render() [==] '

  Test
  '

##### Return values

static —

#### text()

Form.php : 794

Create an input element of type "text".

`public static text([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => '#FFF', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-color'))->render() [==] '

  Test
  '

##### Return values

static —

#### textarea()

Form.php : 821

Create an input element of type "textarea".

`public static textarea([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 1, 'label' => 'Test'))->render() [==] 'Test <textarea name="test_id" id="test_id" title="Test">1</textarea>'

assert

  (array('id' => 'test_id', 'value' => '#FFF', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-file'))->render() [==] '

  Test<textarea name="test_id" id="test_id" title="Test">#FFF</textarea>
  '

##### Return values

static —

#### time()

Form.php : 840

Create an input element of type "time".

`public static time([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => '00:00', 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => '00:00', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-clock'))->render() [==] '

  Test
  '

##### Return values

static —

#### url()

Form.php : 860

Create an input element of type "url".

`public static url([array<string|int, mixed> $attributes = [] ]) : static`

##### Parameters

$attributes : array<string|int, mixed> = []

  An array of attributes for the input field.

##### Tags

assert

  (array('id' => 'test_id', 'value' => 'kotchasan.com', 'label' => 'Test'))->render() [==] 'Test '

assert

  (array('id' => 'test_id', 'value' => 'kotchasan.com', 'label' => 'Test', 'itemClass' => 'item' , 'labelClass' => 'icon-world'))->render() [==] '

  Test
  '

##### Return values

static —

#### create()

Form.php : 670

Creates an HTML element with the specified attributes and inner HTML.

`private static create(string $elem, string $id, string $class, string $innerHTML) : string`

##### Parameters

$elem : string

  The HTML element tag name

$id : string

  The value of the 'id' attribute

$class : string

  The value of the 'class' attribute

$innerHTML : string

  The inner HTML content of the element

##### Return values

string —

The generated HTML element

## Search results