Trongate PHP Framework Docs
Introduction
Quick Start
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Security
Tips And Best Practices

Textareas and Dropdowns

Two more essential form elements: multi-line text and select menus.

Textareas

Use for multi-line text input:

Output:

With a Default Value

With Attributes

Repopulating After Validation Errors

Best Practice: Always pass form data from controller to view. The controller should fetch submitted data and pass it to the view.

In your controller:

If the form hasn't been submitted, this displays empty. If validation failed, it shows what the user typed.

Dropdowns (Select Menus)

Use to create select menus. The pattern is slightly different:

  • $name - the field name (required)
  • $options - array of options (required)
  • $selected - the selected value (optional)
  • $attributes - array of HTML attributes (optional)

Basic Example

Output:

With a Selected Value

Controller prepares the data:

The appropriate option will be selected based on the $size variable.

With Attributes

Real-World Example: Status Selector

Building Options from a Database

The most common pattern is building dropdown options from database records. The controller builds the options array and passes it to the view:

Adding a Blank Option

Start with an empty or "please select" option:

Working with Create/Update Forms

Here's the standard pattern for dropdowns that work for both creating and updating records:

Multiple Selections

Allow users to select multiple options:

Important notes:

  • The field name must end with [] to receive an array
  • Add 'multiple' => 'multiple' to attributes
  • On submission, returns an array of selected values

Pre-selecting Multiple Options

Common Textarea Attributes

Attribute Purpose Example
rows Visible lines ['rows' => '10']
cols Visible width ['cols' => '50']
placeholder Hint text ['placeholder' => 'Enter text...']
maxlength Character limit ['maxlength' => '1000']
required HTML5 validation ['required' => 'required']

Common Dropdown Attributes

Attribute Purpose Example
multiple Allow multiple selections ['multiple' => 'multiple']
size Visible options ['size' => '5']
required HTML5 validation ['required' => 'required']
disabled Disable selection ['disabled' => 'disabled']

Both and automatically escape output for XSS protection.

We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.

Share your thoughts in the Documentation Feedback.

Leave Feedback About This Page