HomeDocumentationTutorialsAdding a Mobile Number Field to Forms

Adding a Mobile Number Field to Forms

Overview

In this tutorial, we'll cover how to add a mobile number field to your forms using a method from your configuration object, $objConfig->mobile('field_name', 'field_label', $required = 0);. This method takes three parameters:

 

  • field_name: The name attribute for the mobile number  input.
  • field_label: The label that will be displayed alongside the mobile number  input.
  • $required: An optional parameter (default is 0) that specifies whether the input is required (1) or not (0).

 

This example shows how to add a mobile number field.

 

PHP
 // Adding a required mobile number field
$objConfig->mobile('field_name', 'field_label', $required = 1);

 

Configuring the Maximum Number of Digits

To ensure that the mobile number does not exceed a certain number of digits, you can chain the max method after the mobile method. This example shows how to add a mobile number field that expects a maximum of 10 digits.

 

PHP
 // Adding a mobile number field with a maximum of 10 digits
$objConfig->mobile('field_name', 'field_label', $required = 1)->max(10);

 

In this example:

 

  • 10: The maximum number of digits expected in the mobile number.

 

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

 

PHP
// Adding your mobile number 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 mobile number fields into your PHP forms using $objConfig->mobile('field_name', 'field_label', $required = 0);. We also covered how to configure the maximum number of digits for the mobile number field using $objConfig->mobile('field_name', 'field_label', $required = 0)->max(10);.