HomeDocumentationTutorialsIncluding a text field in my forms

Including a text field in my forms

Overview

In this tutorial, we'll cover how to add a text field to your forms. This method allows you to integrate text inputs seamlessly into your application forms. The method  takes three parameters:

 

  • field_name: The name attribute for the text input.
  • field_label: The label displayed alongside the text input.
  • $required: Indicating if the text input is required (1) or not (0).

 

This example shows how to add a text field to your form.

 

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

 

Adding a Text Field with a Maximum Number of Characters

To set the maximum number of characters allowed in the text field, you can chain the max() method after the text() method. This example shows how to add a text field with a maximum of 255 characters.

 

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

 

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 text  fields are correctly initialized and integrated into your form. This example shows how to configure the add and edit fields.

 

PHP
// Adding your text 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 text fields into your forms using $objConfig->text('field_name', 'field_label', $required = 0);. This method provides flexibility in configuring text inputs according to your application's needs.

 

We also covered how to set the maximum number of characters allowed in the text field using $objConfig->text('field_name', 'field_label', $required = 0)->max(255);.