Custom Plugins addon settings add an input to upload a files

Hello i made custom plugin addon for gravity forms and inside the settings i want have a settings who upload an pdf is it possible ?

Yes, adding an upload field for a PDF file to the settings of your custom plugin addon for Gravity Forms is indeed possible.

Gravity Forms provides a file upload field type that can be used to upload PDF files or any other file type. To add a file upload field to your plugin’s settings, you can use the add_settings_field() function to add a new field to the plugin’s settings page. Within the callback function for the field, you can use the GF_Field_FileUpload::settings_field() method to render the file upload field.

Here’s an example code snippet that demonstrates how to add a file upload field to your plugin’s settings:

// Add a new field to the settings page of your plugin
add_settings_field(
    // The ID of the new field
    'pdf_file_upload',
    // The label for the new field
    'PDF File Upload',
    // The callback function that will render the new field
    function() {
        // Create a new instance of the GF_Field_FileUpload class
        $field = new GF_Field_FileUpload();
        // Set the ID of the file upload field
        $field->id = 'pdf_file_upload';
        // Set the label of the file upload field
        $field->label = 'PDF File Upload';
        // Render the title and settings of the file upload field
        $field->get_form_editor_field_title();
        $field->get_form_editor_field_settings();
        // Set the 'multiple_files' setting to false to allow only one file upload
        $field->settings['multiple_files'] = false;
        // Set the 'allowedExtensions' setting to 'pdf' to restrict the file type to PDF
        $field->settings['allowedExtensions'] = 'pdf';
        // Render the file upload field
        $field->settings_field('', false);
    },
    // The page on which the new field should be displayed
    'my_plugin_settings_page',
    // The section of the page in which the new field should be displayed
    'my_plugin_settings_section'
);

In this example, the add_settings_field() function adds a new field with the ID pdf_file_upload to the settings page for your plugin. The callback function for the field uses the GF_Field_FileUpload::settings_field() method to render the file upload field. The allowedExtensions setting restricts the file type to PDF files.

You’ll need to modify this example code to fit the specific requirements of your plugin, but it should give you a good starting point for adding a PDF file upload field to your plugin’s settings.

Ref: https://docs.gravityforms.com/gf_field_fileupload/

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.