HomeDocumentationTutorialsAdding a Text area to Forms

Adding a Text area to Forms

Overview

In this tutorial, we'll cover how to add a textarea to your forms using a method from your configuration object, $objConfig->textarea('field_name', 'field_label', $required = 0);.  This method allows you to integrate textareas seamlessly into your forms. Additionally, we'll explain how to configure the maximum number of characters in the textarea.  

 

The method $objConfig->textarea('field_name', 'field_label', 0); takes three parameters:

 

  • field_name: The name attribute for the textarea input.
  • field_label: The label displayed alongside the textarea input.
  • $required = 0: Indicates that the field is not required.

 

Example Code

 

PHP
// Adding a textarea field
$objConfig->textarea('field_name', 'field_label', $required = 0);

 

This example adds a textarea field named 'Comments' to your form. Adjust the parameters (field_name, field_label, and $required) as per your specific requirements.

 

Configuring the Maximum Number of Characters

To ensure that the textarea does not accept more than a specified number of characters, you can chain the max method after the textarea method. This example shows how to add a textarea field with a maximum of 320 characters.

 

PHP
// Adding a textarea field with a maximum of 320 characters
$objConfig->textarea('field_name', 'field_label', $required = 0)->max(320);

 

In this example:

  • 320: The maximum number of characters allowed in the textarea.

 

Configuration in Your Application

For the configuration to work properly, it's important to include the 'field_name'   amongst the `addFields` and `editFields`. This ensures that the textarea  fields are correctly initialized and integrated into your form. This example shows how to configure the add and edit fields.

 

PHP
// Adding your textarea field to the add and edit forms
$objConfig->addFields(array('field_name'));
$objConfig->editFields(array('field_name'));

 

Conclusion

By following these steps, you can easily integrate textareas into your PHP forms using $objConfig->textarea('field_name', 'field_label', $required = 0);. We also covered how to configure the maximum number of characters for the textarea field using $objConfig->textarea('field_name', 'field_label', $required = 0)->max(320);.