When upload files and add a custom action… The file doesnt upload correctly. I get the URL but the image never uploads:
/**
* FORM TEST
*/
add_action( 'bricks/form/custom_action', 'url_test', 10, 1 );
function url_test( $form ) {
$form_fields = $form->get_fields();
$settings = $form->get_settings();
$form_id = $form_fields['formId'];
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
// Check if the form id is the one you want
if( $form_id !== 'gfseuh' ) return;
// Obtener los archivos subidos desde el formulario
$uploaded_files = $form->get_uploaded_files();
// Verificar si el campo "form-field-sajbjc" existe en los archivos subidos
if (isset($uploaded_files['form-field-wfkglc'])) {
// Acceder al primer elemento del campo "form-field-sajbjc" para obtener la URL
$url = $uploaded_files['form-field-wfkglc'][0]['url'];
// Actualizar el campo de tipo imagen del usuario actual
update_field('test_url', $url, 'user_' . $user_id);
} else {
$url = 'Nada :(';
// Actualizar el campo de tipo imagen del usuario actual
update_field('test_url', $url, 'user_' . $user_id);
}
}
I created an text field called “test_url” and it receives the url, but the files in this no exists. Any idea?
from get_uploaded_files, but the file is being uploaded at a different URL:
/wp-content/uploads/2023/10/gszqky651ee1bb970d26.91396348_FBL-Redemption-Partner-List-September.pdf
After downloading Bricks 1.9.2 beta I’m still having a very similar issue. I’ve created a custom action to send form data to Telegram. When sending and checking the file URL after it was sent, that file doesn’t exist.
Here’s a piece of what I have:
function telegram_send( $form ) {
// Get information about uploaded files
$uploaded_files = $form->get_uploaded_files();
// Check if there are uploaded files
if (!empty($uploaded_files)) {
$telegram_message .= "Uploaded files:\n";
foreach ($uploaded_files as $field_id => $files) {
foreach ($files as $file) {
// Add only the file URL to the message
$telegram_message .= $file['url'] . "\n";
}
}
}
}
Thank you. I did not, but I have now. And it works when I choose to save the file in media library, but doesn’t work when I save the file in custom directory.
When saving the file in custom directory the sent URL looks like this /wp-content/uploads/uploaded-file.jpg. It’s missing /custom-directory/.
As this is your custom code, please print_r or var_dump the $file inside your second foreach loop.
You should be able to find the physical location of the file in $file['file']
The $file['url'] is just a temp location upon upload.
If you still encounter issues, I would appreciate it if you could create a new thread
I have switched over from [‘url’] to [‘file’], but the outcome is the whole directory where this image lies. (/var/www/vhosts/domain.com/httpdocs/wp-content/uploads/profileimg/Screenshot_119.jpg)
The problem is, that way I can not use this to display dynamic images inside bricks.
Every website setup has different way to organize their WP site.
The upload folder structure in WordPress may vary from one site to another; some may have custom directories that are not directly accessible. Some may not inside uploads folder as well. Hence, we cannot build exact final accessible URL from the function.
If you are using default structure, this code should be able to build the URL.