Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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".

share|improve this answer
    
That filter specifically affects the "List" form element which allows repeatable fields. –  Dom Mar 8 '13 at 9:50

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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