Try this
function my_custom_form_submission( $contact_form ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$data = $submission->get_posted_data();
$email = isset( $data['your-email'] ) ? sanitize_email( $data['your-email'] ) : '';
$phone="Nincs megadva";
$lastname = isset( $data['your-name'] ) ? sanitize_text_field( $data['your-name'] ) : '';
$firstname = isset( $data['text-532'] ) ? sanitize_text_field( $data['text-532'] ) : '';
$companyname = isset( $data['text-479'] ) ? sanitize_textarea_field( $data['text-479'] ) : '';
$created = current_time( 'Y-m-d\TH:i:s' );
$branch = isset( $data['menu-586'] ) ? sanitize_textarea_field( $data['menu-586'] ) : '';
if ( $branch == 'Divat / Design' ) {
$flow = 'DivatDesign';
} else {
$flow = 'Startup';
}
$uploaded_files = $submission->uploaded_files();
$documents = [];
if ( ! empty( $uploaded_files ) ) {
$uploaded_file = $uploaded_files['file-524'];
// Read file contents
$file_content = file_get_contents( $uploaded_file );
if ( $file_content !== false ) {
// Encode file content in base64
$base64_file = base64_encode( $file_content );
// Prepare data array for API
$documents = [
[
'FileName' => basename( $uploaded_file ),
'MimeType' => mime_content_type( $uploaded_file ),
'Base64' => $base64_file,
],
];
}
}
if ( wf_checkEmail( $email ) == false ) {
$userId = saveToWf( $email, $lastname, $firstname );
// Log the userId for debugging
error_log( 'User ID: ' . $userId );
if ( $userId ) {
registerToWf( $email, $lastname, $firstname, $flow, $userId, $companyname, $phone, $attachedfile, $branch, $documents );
}
}
}
}
add_action( 'wpcf7_before_send_mail', 'my_custom_form_submission' );
Make sure the file-524
matches the name of the file upload field in your Contact Form 7 setup. Also, ensure the file permissions allow reading the uploaded file on the server.
To debug the issue, you can temporarily add error logging to check the contents of $uploaded_files
:
error_log( print_r( $uploaded_files, true ) );
This will help you see what $uploaded_files
actually contains and adjust your code accordingly.