Default File Protection Option in Formidable Forms

By: Ernesto Serrano | Asked: 07/25/2024
ForumsCategory: Code SnippetsDefault File Protection Option in Formidable Forms
Ernesto Serrano asked 4 months ago

Dear Formidable Community,

We are intensive users of Formidable and greatly appreciate the functionality it provides. However, we had a specific need regarding the protection of uploaded files. Most of the files uploaded through our forms need to be protected, but our users often forgot to check the “Protect files” checkbox. Considering that this checkbox needs to be checked 99% of the time, we sought a way to have the “Protect files” checkbox marked by default.
To resolve this issue, we developed our own plugin to enforce file protection by default. Below is the code we are using:

<?php
/*
Plugin Name: Formidable Force File Protection
Description: Forces file protection for file uploads in Formidable Forms.
Version: 1.0
Author: Ernesto
*/

// Hook to force file protection when creating a new form entry
add_action('frm_after_create_entry', 'force_file_protection_on_create', 20, 2);

function force_file_protection_on_create($entry_id, $form_id) {
    // Get the values of the newly created form entry
    $values = FrmEntry::getOne($entry_id, true);

    // Force file protection and no indexing
    $values->options['protect_files'] = 1; // Force file protection
    $values->options['noindex_files'] = 1; // Force no indexing of files

    // Update the entry with the new values
    FrmEntry::update($entry_id, array('options' => $values->options));
}
?>

This solution has helped us ensure that files are protected by default. We are sharing this in case it can be useful to other users with similar requirements.

Thank you very much for your consideration.

Best regards,

Ernesto

 
1 Answers
Victor Font answered 4 months ago
We are not the Formidable Team. This is a community forum where questions are answered by end users just like you. If you have a feature request, please open a ticket with Strategy 11 support.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right