To add a custom dropdown with values dynamically fetched from the database in the lead form of vTiger, you need to perform the following steps:
1. Create a Custom Field for Dropdown
First, create a custom dropdown field in the Leads module.
- Go to the vTiger CRM dashboard.
- Navigate to CRM Settings > Module Management > Module Layouts and Fields.
- Select the Leads module and click Add Custom Field.
- Choose Picklist (Dropdown) as the field type and give it a suitable label.
- Save the custom field.
2. Modify the Database to Fetch Dynamic Values
If you want to fetch dropdown values dynamically from your database (e.g., from a custom table), you’ll need to modify the code.
Steps:
- Create a Table to Store Dropdown Values:
Create a table in the database to store the dynamic values for your dropdown.
CREATE TABLE custom_dropdown_values (
id INT AUTO_INCREMENT PRIMARY KEY,
value VARCHAR(255) NOT NULL
);
Insert some initial values:
INSERT INTO custom_dropdown_values (value) VALUES ('Value 1'), ('Value 2'), ('Value 3');
- Modify the Code to Fetch Values Dynamically: You’ll need to modify the core files to dynamically populate the dropdown values.
- Go to the Leads module’s layout template file, typically located at:
modules/Leads/DetailView.php
- Modify the part of the form where the custom dropdown is being rendered. You can use a PHP query to fetch the values from the database. Example:
global $adb;
$query = "SELECT value FROM custom_dropdown_values";
$result = $adb->pquery($query, array());
$dropdown_values = array();
while ($row = $adb->fetch_array($result)) {
$dropdown_values[] = $row['value'];
}
// Output the dropdown in HTML
echo '<select name="custom_field_dropdown">';
foreach ($dropdown_values as $value) {
echo '<option value="'.$value.'">'.$value.'</option>';
}
echo '</select>';
3. Ensure Values are Saved and Retrieved Properly
Ensure the system saves the selected value in the database when the form is submitted. Check the appropriate handler file, usually under:
modules/Leads/Save.php
Update the code to handle the saving of the selected dropdown value into the vtiger_leadscf (custom fields) table.
4. Test the Form
After implementing these changes, test the lead form by navigating to the Leads module, creating a new lead, and checking if the dropdown is populated with dynamic values from your database. Also, ensure that the selected value is saved properly.
Conclusion
To simply add a custom dropdown with all needed values dynamically gotten easily from the database in the lead form of vTiger, you just want to perform the various above-mentioned steps while having the best Vtiger hosting solutions.