如何使用“gform_save_field_value”过滤器在Gravity Forms中修改上传的文件URL

时间:2015-08-05 10:07:04

标签: wordpress gravity-forms-plugin

我希望在用户提交Gravity表单时保存到数据库之前修改上传的文件URL。

我试图通过在Gravity表单中使用“gform_save_field_value”过滤器来实现此目的。但是当我在过滤器功能中打印字段时,我从未获得文件上载字段ID。除文件上传输入字段外,所有其他字段都可在过滤器功能中访问。

 add_filter( 'gform_save_field_value', 'save_field_value', 10, 4 );
 function save_field_value( $value, $lead, $field, $form ) {
    print_r($field);
 }

1 个答案:

答案 0 :(得分:1)

The gform_upload_path filter will allow you to change the upload path of the file (and the URL).

add_filter( 'gform_upload_path', 'change_upload_path', 10, 2 );
function change_upload_path( $path_info, $form_id ) {
   $path_info['path'] = '/home/public_html/yourdomainfolder/new/path/';
   $path_info['url'] = 'http://yourdomainhere.com/new/path/';
   return $path_info;
}

If you need to change the actual name of the file, here is a snippet that makes it a cinch.

http://gravitywiz.com/rename-uploaded-files-for-gravity-form/