- Getting Started
- Field Types
- Email Notifications
-
Integrations
- MailerLite
- Create User Accounts with Convert Forms
- MailChimp
- HubSpot
- GetResponse
- AcyMailing
- Content App
- Webhooks Addon
- Facebook Meta Pixel
- Google Adwords
- Sync submissions with your favorite app
- Drip Ecommerce CRM
- Google Analytics
- Constant Contact
- SalesForce Web-to-Lead
- IContact
- Zoho CRM
- Elastic Email
- Zoho Campaigns
- Zapier
- ConvertKit
- Brevo (Sendinblue)
- Campaign Monitor
- AWeber
- ActiveCampaign
-
Functionality
- Scroll the Page to the Top When a Long Form is Submitted
- Display Submissions Count for a Specific Form
- Populate Drop Down, Radio Buttons or Checkboxes with a CSV File
- Automatically Delete Submissions Older Than X Days
- Silently POST Submitted Data to Any API or URL
- Automatically Save Each Submission to a JSON file
- Authenticate and Login a User with a Custom Joomla Form
- Auto-Populate a Form Field with an Article Data
- Add a placeholder text to a Dropdown
- Create Multilingual Forms in Joomla
- Create a custom Joomla User Registration Form
- Redirect User to a URL After Form Submission
- Export and Import Forms across different Websites
- Export Form Submissions to CSV
- Convert Forms
- Styling and Customization
- Payment Forms
- Advanced Features
- Developers
- Troubleshooting and Support
-
Spam, Security & Compliance
- Enforcing a Custom Password Policy in Convert Forms
- Add Cloudflare Turnstile to your Joomla Form
- Implement the Iubenda Consent Database in Joomla with Convert Forms
- Add Custom Validations to Fields and Forms
- Add Math Captcha to your Form
- Prevent a Field From Saving in the Database
- Add hCaptcha to your Form
- Enable Double Opt-in
- Allow Form Submissions in Specific Date Range
- Ensure a Unique Value is Entered Into a
- Block Form Submissions Containing Profanity (Bad Words)
- Block Email Addresses or Email Domains
- Native Convert Forms Anti-spam Protection with Honeypot
- Add reCAPTCHA to your Form
- Create GDPR Compliant Forms
Populate Drop Down, Radio Buttons or Checkboxes with a CSV File
You can easily popoulate your Drop Down, Radio Buttons as well as Checkboxes fields using a CSV file without having to enter each choice one by one by yourself. This will help you save a lot of time if you have a large list of options. Below you can find a step by step tutorial on how to populate your fields.
- What is a CSV file?
- Create the CSV file
- Upload CSV file to your server
- Create your field
- Add the PHP Snippet
1. What is a CSV file?
CSV stands for comma separated value. A CSV or .csv file is a delimited text file that uses a comma to separate values. CSV files can be imported to and exported from programs that store data in tables, such as Microsoft Excel or Google Sheets. For example, let's say you had a spreadsheet containing the following data.
Label | Value | Calc Value |
---|---|---|
Mars | 5 | 500 |
Jupiter | 50 | 250 |
Earth | 15 | 60 |
Moon | 35 | 380 |
The above data could be represented in a CSV-formatted file as follows:
Mars,5,500
Jupiter,50,250
Earth,15,60
Moon,35,380
Here, the fields of data in each row are delimited with a comma and individual rows are separated by a newline.
2. Create the CSV file
First of all, you need to create a CSV file if you have not yet created one. This CSV file needs to be comma-separated and have the following format:
Label,Value,Calculation Value |
Label: Label of the item
Value: Value of the item
Calculation Value: Value used in the calculations of the item
Value and Calculation Value are optional and may not be included in the CSV.
Example containing only labels:
Option 1
Option 2
Option 3
Example containing labels and values:
Option 1,5
Option 2,10
Option 3,15
Example containing labels, values and calculation values:
Option 1,5,50
Option 2,10,100
Option 3,15,150
3. Upload CSV file to your server
After you have created your CSV file, its now ready to be uploaded to your server. Log into your administrator panel > Content > Media > upload your CSV file or use a FTP software of your choice to upload the CSV file to your desired location.
4. Create your field
This field can either be a dropdown, radio buttons or checkboxes.
One you have created your field, set the Field Name.
4. Add the PHP Snippet
Copy the following PHP snippet and paste it in your form > Behavior > PHP Scripts > Form Prepare
// Enter the Field Name of the field you created above
$choices_field_name = 'dropdown';
// Enter path to CSV file starting from your Joomla root directory
$file_path = 'media/csv/cf_data.csv';
// Do not edit below
$file_path = JPATH_SITE . '/' . ltrim($file_path, '/');
if (!\JFile::exists($file_path))
{
return;
}
if (!$contents = file_get_contents($file_path))
{
return;
}
// remove previous choices
unset($form['fields'][$choices_field_name]['choices']['choices']);
// add CSV choices
foreach(preg_split("/((\r?\n)|(\r\n?))/", $contents) as $line)
{
$data = explode(',', $line);
$label = isset($data[0]) ? $data[0] : false;
if (!$label)
{
continue;
}
$form['fields'][$choices_field_name]['choices']['choices'][] = [
'label' => $label,
'value' => isset($data[1]) ? $data[1] : '',
'calc-value' => isset($data[2]) ? $data[2] : ''
];
}
Finally, you need to set which Field will be populated as well as define the CSV file path. To do so, in the above code you copy/pasted, set the Field Name as well as the path to the CSV file in the following variables:
// Enter the Field Name of the field you created above
$choices_field_name = 'dropdown';
// Enter path to CSV file starting from your Joomla root directory
$file_path = 'media/csv/cf_data.csv';
Note: $file_path needs to start from the root directory of your Joomla installation.