spivurno
7/21/2014 - 2:18 PM

Gravity Wiz // Gravity Forms // Field-specific Upload Path (Simple)

Gravity Wiz // Gravity Forms // Field-specific Upload Path (Simple)

<?php
/**
 * Gravity Wiz // Gravity Forms // Field-specific Upload Path
 *
 * Provides a method for specifying field-specific file upload paths.
 *
 * @version	 1.0
 * @author    David Smith <david@gravitywiz.com>
 * @license   GPL-2.0+
 * @link      http://gravitywiz.com/...
 */
class GF_Field_Specific_File_Upload_Path {

    var $current_field_id = null;

    function __construct() {

        add_filter( 'gform_save_field_value', array( $this, 'stash_current_field_id' ), 10, 3 );
        add_filter( 'gform_upload_path', array( $this, 'modify_upload_path' ) );

    }

    function stash_current_field_id( $value, $entry, $field ) {
        $this->current_field_id = $field['id'];
    }

    function modify_upload_path( $upload_path ) {

        // modify the upload path based on the current field ID:
        // $current_field_id = $this->current_field_id

        return $upload_path;
    }

}

new GF_Field_Specific_File_Upload_Path();