# Forms

{% hint style="danger" %}
**Please note:** This page is under construction and has not been finished yet.
{% endhint %}

## Introduction

Use the following to retrieve the form class object

```php
$frm = e107::getForm();
```

## Forms methods

### open()

Returns a form opening tag.

```php
$frm->open('myform'); 
```

```php
$frm->open('myform', 'get', 'myscript.php', array('autocomplete' => 'on', 'class' => 'formclass'));
```

| Parameter | Type   | Description                                                                                                                                           | Mandatory                     |    |
| --------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | -- |
| **name**  | string | Name of the form                                                                                                                                      | **Yes**                       |    |
| mode      | string | <p>post                                                                                                                                               | get <br>'post' by default</p> | No |
| target    | string | <p>The request URL <br><code>e\_REQUEST\_URI</code> by default</p>                                                                                    | No                            |    |
| options   | array  | <p>Specify options such as class or autocomplete</p><p></p><ul><li>autocomplete - on/off (boolean)</li><li>class - (any string)</li><li>...</li></ul> | No                            |    |

### close()

Returns a form closing tag

```php
$frm->close();
```

### text()

Returns a text field form element

```php
$frm->text('my-field', 'current_value', 100, array('size' => 'large')); // returns <input class="tbox input-large" id="my-field" maxlength="100" name="my-field" type="text" value="current_value"></input>
```

| Parameter | Type    | Description                                                                                                                                                                                                   | Mandatory |
| --------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
| name      | string  | Name of the text field                                                                                                                                                                                        |           |
| value     | string  | Value of the text field                                                                                                                                                                                       |           |
| maxlength | integer | Specifies the maxlength element of the text field                                                                                                                                                             |           |
| options   | array   | <p>Specify options such as class, size or selectize<br></p><ul><li>class: (any string)</li><li>size: mini, small, medium, large, xlarge, xxlarge</li><li>selectize: array with selectize.js options</li></ul> |           |

### textarea()

```php
$frm->textarea($name, $value, $rows, $cols, $options, $counter);
```

### bbarea()

```php
$frm->bbarea($name, $value, $template, $mediaCat, $size, $options);
```

| Parameter | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Mandatory |
| --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
| **name**  | string | Name of the field                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | **Yes**   |
| **value** | string | Contents of the field                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | **Yes**   |
| template  | string | <p>A string defining the button template to use with bbarea. Included in the core are the following: news, submitnews, extended, admin, mailout, page, comment, signature<br><br>But you can also use the name of the plugin (e.g. forum) if the plugin provides a bbcode\_template.php</p>                                                                                                                                                                                                                                                                                                    | No        |
| mediaCat  | string | <p>Name of the media catalog to use <br>(default: \_common)</p><p><br><em>Is only used by TinyMCE plugin (if installed and used)</em></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                      | No        |
| size      | string | <p>Size of the bbarea/editor.<br>Use one of the following values: tiny, small, medium, large <br>(default: large)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | No        |
| options   | array  | <p>Array with options to use with the editor:<br>id: string - In case the bbarea/editor id should be different to the name<br>class: string - the css classes to use<br>counter: boolean - Show a character counter<br>wysiwyg: boolean/string -</p><ul><li>False in case you want disable the wysiwyg editor for this field and use the default bbcode editor.</li><li>True to enable the current installed (and enabled) wysiwyg editor</li><li>Name of the editor (e.g. tinymce4 or simplemde) to use, in case wysiwyg is generally enabled and the supplied editor is installed.</li></ul> | No        |

### select()

```php
$frm->select($name,$option_array,$selected,$options,$defaultBlank);
```

### checkbox()

```php
$frm->checkbox($name,$value,$checked,$options);
```

### hidden()

```php
$frm->hidden($name,$value,$options);
```

### button()

```php
$frm->button($name,$value,$action,$label,$options);
```

### carousel()&#x20;

Render a Bootstrap carousel

```php
$frm->carousel($name, $array, $options);
```

```php
$array = array(
      'slide1' => array('caption' => 'Slide 1', 'text' => 'first slide content' ),
      'slide2' => array('caption' => 'Slide 2', 'text' => 'second slide content' ),
      'slide3' => array('caption' => 'Slide 3', 'text' => 'third slide content' )
  );

echo $frm->carousel('my-carousel', $array);
```

### tabs()&#x20;

Render Bootstrap tabs

```php
$frm->tabs($array,$options);
```

```php
$array = array(
   'home'  => array('caption' => 'Home', 'text' => 'some tab content' ),
   'other' => array('caption' => 'Other', 'text' => 'second tab content' )
);

echo $frm->tabs($array);

echo $frm->tabs($array, array('active' => 'other')); // make 'other' the initial active tab. 
```

### datepicker()

Date field with popup calendar. Returns UNIX timestamp or string value on submit.

```php
$frm->datepicker($name, $datestamp = false, $options = null)
```

| Parameter | Type             | Description                                                                                                                                                                                                                                                                                                     | Mandatory? |
| --------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| **name**  | string           | The name of the field                                                                                                                                                                                                                                                                                           | **Yes**    |
| datestamp | integer\|boolean | <p>UNIX timestamp. Set the default value of the field.</p><p><em>Default:</em> false</p>                                                                                                                                                                                                                        | No         |
| options   | array\|string    | <p>Available options (see <a href="/pages/-M8AHnecKxhYmHJUvikL#examples">examples</a> below):</p><ul><li>mode - 'date' or 'datetime'</li><li>format - </li><li>timezone</li><li>size</li><li>required (true/false)</li><li>firstDay</li><li>disabled</li><li>placeholder</li></ul><p><em>Default: null</em></p> | No         |

{% hint style="info" %}
**TODO:** Clarify possible options and add more examples
{% endhint %}

#### *Examples:*

```php
$frm->datepicker('my_field',time(),'mode=date');
$frm->datepicker('my_field',time(),'mode=datetime&inline=1');
$frm->datepicker('my_field',time(),'mode=date&format=yyyy-mm-dd');
$frm->datepicker('my_field',time(),'mode=datetime&format=MM, dd, yyyy hh:ii');
$frm->datepicker('my_field',time(),'mode=datetime&return=string');
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devguide.e107.org/classes-and-methods/forms.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
