Tell me more ×
WordPress Answers 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

1 Answer

up vote 1 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 at 9:50

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.