Home › Forums › Quform WordPress › ِA link to download dropdown menu items
- This topic has 5 replies, 2 voices, and was last updated 1 week, 1 day ago by
Abbas.
- AuthorPosts
- June 17, 2025 at 4:50 pm #37829
Abbas
ParticipantHello,
Many of the forms I create using Quform include a dropdown list of school names. To keep track of which schools have completed the form, I previously asked for a way to hide schools that had already filled it out, and the code you provided worked wonderfully.
( https://gist.github.com/ThemeCatcher/c7dbe8e7598b013603d2ea3a2acbd77e )
However, for ongoing tracking, I’d like a download link for a text file (the link can be placed next to the drop-down menu) or a page that displays the names of the remaining schools, with each school name on a new line.
Regards,
AbbasJune 19, 2025 at 11:14 am #37830Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 19, 2025 at 11:18 am #37831Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 20, 2025 at 7:31 am #37832Abbas
ParticipantHi
Very cool… and I’m grateful.
I modified the code so I can download the text file for any form.
I tested the modified code and it works great. But, in your opinion, is it good and secure?
Here’s the modified code:
(Modified with the help of DeepSeek AI)add_action(‘init’, function () {
// Check if the required parameters exist and Quform is active
if (!isset($_GET[‘download_schools_txt’]) || !isset($_GET[‘id’]) || !class_exists(‘Quform’)) {
return;
}// Sanitize and validate the element ID (should be in format number_number e.g. 158_3)
$id = sanitize_text_field($_GET[‘id’]);
if (!preg_match(‘/^\d+_\d+$/’, $id)) {
wp_die(‘Invalid element ID’, ‘Error’, array(‘response’ => 400));
}// Extract form ID from the element ID
list($form_id) = explode(‘_’, $id);// Get form configuration
$config = quform(‘repository’)->getConfig($form_id);if (!is_array($config)) {
wp_die(‘Form not found’, ‘Error’, array(‘response’ => 404));
}// Create form instance
$form = quform(‘formFactory’)->create($config);
$select = $form->getElement(“quform_$id”);if (!$select instanceof Quform_Element_Select) {
wp_die(‘Specified element is not a select dropdown’, ‘Error’, array(‘response’ => 400));
}global $wpdb;
// Query to get submitted values for this element
$query = $wpdb->prepare(
“SELECT ed.value
FROM {$wpdb->prefix}quform_entry_data ed
LEFT JOIN {$wpdb->prefix}quform_entries e
ON ed.entry_id = e.id
WHERE e.form_id = %d AND e.status = ‘normal’ AND ed.element_id = %d”,
$form->getId(),
$select->getId()
);$submitted = $wpdb->get_col($query);
$available_options = array();// Collect options that haven’t been submitted
foreach ($select->getOptions() as $option) {
if (isset($option[‘value’]) && !in_array($option[‘value’], $submitted, true)) {
$available_options[] = $option[‘label’];
}
}// Generate file content
$file_content = join(“\n”, $available_options);// Create filename with element ID and timestamp
$filename = sprintf(‘available_options_%s_%d.txt’, $id, time());// Send HTTP headers for file download
header(‘Content-Type: text/plain’);
header(‘Content-Disposition: attachment; filename=”‘ . $filename . ‘”‘);
header(‘Content-Length: ‘ . strlen($file_content));
header(‘Pragma: no-cache’);
header(‘Expires: 0’);// Output content and terminate
echo $file_content;
exit;
});Regards,
Abbas- This reply was modified 1 week, 1 day ago by
Abbas.
June 20, 2025 at 9:30 am #37834Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 20, 2025 at 9:49 am #37835Abbas
ParticipantThank you so much.. I am grateful for you and the wonderful support
- This reply was modified 1 week, 1 day ago by
- AuthorPosts
- You must be logged in to reply to this topic.