0

I am looking to use the gform_column_input_content filter to make a repeatable file upload element. The filter modifies the HTML content of the list field column input tag.

The following code provided from the docs shows how to replace the default text input with a textarea input.

<?php
add_filter("gform_column_input_content_21_9_3", "change_column3_content", 10, 6);
function change_column3_content($input, $input_info, $field, $text, $value, $form_id){
    //build field name, must match List field syntax to be processed correctly
    $input_field_name = 'input_' . $field["id"] . '[]';
    $tabindex = GFCommon::get_tabindex();
    $new_input = '<textarea name="' . $input_field_name . '" ' . $tabindex . ' class="textarea medium" cols="50" rows="10"></textarea>';
    return $new_input;
}
?>

I want to replace this with a File Upload field, but I'm pretty much stumped as where to go from here. Surely just filtering the File Upload elements HTML won't result in a working File Upload element?

2 Answers 2

1

The following provides you with a file upload:

add_filter("gform_column_input_content_21_9_3", "change_column3_content", 10, 6);
function change_column3_content($input, $input_info, $field, $text, $value, $form_id) {
    $input_field_name = 'input_' . $field["id"] . '[]';
    $tabindex = GFCommon::get_tabindex();
    $new_input = '<input type="file" name="' . $input_field_name . '" ' . $tabindex . ' class="YOUR-CSS-CLASSES" />';
    return $new_input;
}

But what does 'repeatable' mean in this context? Do you want an input for multiple file uploads?

// Edit

For file uploads, your form needs to have method="post" enctype="multipart/form-data".

2
  • That filter specifically affects the "List" form element which allows repeatable fields.
    – Dom
    Mar 8, 2013 at 9:50
  • This is almost 8 years old, and the latest versions of Gravity Forms have checks in the code that block this method from being used. Nov 19, 2021 at 1:29
0

Here's a more basic piece of code that I used to accomplish this same thing, except I didn't want to just replace a third column, I wanted to change the field from text to an upload field no matter what column it was in.

I placed the following code at the bottom of my theme's functions.php file, which can be found directly under your templates main folder.

add_filter("gform_column_input_content", "change_column_content", 8, 15);
function change_column_content($input, $input_info, $field, $text, $value, $form_id) {
$input_field_name = 'input_' . $field["id"] . '[]';
$tabindex = GFCommon::get_tabindex();
$new_input = '<input type="file" name="' . $input_field_name . '" ' . $tabindex . ' class="YOUR_CSS_CLASS_GOES_HERE" />';
return $new_input;
}

Note that the 8 and 15 will need to be replaced with your own Form ID and Field ID. Also, be sure to change the css class under input type.

Hope this helps someone...cheers!

1
  • This is incorrect. The integers 8 and 15 in the add_filter function are not meant for Form ID and Field ID .. they are meant for filter priority execution and the number of parameters that the callback function will allow. Nov 19, 2021 at 1:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.