Thanks Victor - I have my own function that writes to the debug log. I did not include this part of the code
jm_write_log("5.0 blockfilename=". $filename);
$_POST['item_meta'][$posted_field->id] = $filename;
The $filename is blank
Your if statement will only work for $posted_field->id == 25. Is that the correct field id for the field you want to store the file name? What is the value of $_POST['item_meta'][20]. Did you cross reference $_POST['item_meta'][20] to make sure its value is the same as the attachment id in the media library? What value is wp_get_attachment_url() returning? I would set a break point and examine the values of the $errors, $posted_field, and $posted_value parameters also.
As a follow up - I ran the script as is in the documentation just replacing the field ids as directed with my field ids. Same result nothing no file url
That is the problem the function wp_get_attachment_url() is returning nothing.
That's exactly why I asked if you cross referenced the data. It could be a timing issue with the hook you're using. Make sure the attachment id exists in the media library and that its attachment id matches what's in your field. You also have to ensure you're passing the right value to the WordPress function. You need to use breakpoints when you debug. Look up Kint. That's what we use.
I've given you all the right steps to do. Anything more, is beyond what I can offer in my scope as a community volunteer. Finish troubleshooting as I explained and you'll find the problem. The problem is not with the code, but more likely the data. You need to know the value of everything going through that channel.
When you finish your own debugging, if things don't work out, you may need the help of a developer. Please visit https://formidable-masterminds.com/developers-directory/ to search through a list of the best Formidable talent in the world. No boast.
Thanks Victor there seems to be several problems going on here including with my theme
Hi Victor - I think I found the problem, but I don't know the solution. I am using the code below to change the uploads folder directory and it works fine. The problem is that now the image upload is writing the file with different permissions than it does if it just writes to the default formidable uploads directory. I have turned off all media settings that generate multiple image sizes. Any idea why it is now writing different permissions?
The default permissions: -rw-r--r-- 1 apache apache
The permissions it is writing with the new upload folder: --w------- 1 apache apache
The code to change the upload folder
add_filter( 'frm_upload_folder', 'frm_custom_upload', 10, 2 );
function frm_custom_upload( $folder, $atts ) {
$form_key = FrmForm::get_key_by_id($atts['form_id']);
if ( $form_key == 'sponsor_challenge_block_management0001' ) {
global $current_user;
$folder = "formidable" . '/' . $current_user->user_login;
}
return $folder;
}
File permissions are inherited from the folder. The Formidable upload field doesn't assign permissions to anything it uploads. Permissions are managed solely by your server's operating system. You have to FTP into your site and change the formidable/folder permissions manually and allow the new permissions to cascade to the sub-folders. If "formidable" is a subfolder of the WordPress uploads directory, I don't think you'd be experiencing these permissions issues.
I figured out the permissions were being set by the Forms File Protection. Once I disabled it the permission problem went away. Thanks
Good find! I forgot about Formidable security. It's been a very long time since I've had to use it.
Please login or Register to submit your answer