• Hello,

    i have the problem that with the last updates of Contact Form 7 add_uploaded_file() of the WPCF7_Submission class become private method.
    For this reason, the XML file that is created from the filled-in data is not attached to the mail in the contact form.

    This XML file is needed for further use in hotel software, which is why it is so important that it is an XML file.

    Das Problem ist in der Zeile mit folgenden Code:
    $submission->add_uploaded_file( ‘submission_xml’, ‘anfrage.xml’ );

    Der Code aus der functions.php:

    add_action( 'wpcf7_before_send_mail', 'dp_get_form_values', 10, 1 );
    function dp_get_form_values( $WPCF7_ContactForm ) {
        if ( $WPCF7_ContactForm->id() == 789 || $WPCF7_ContactForm->id() == 1177 ) {
            $instance = WPCF7_ContactForm::get_current();
            $submission = WPCF7_Submission::get_instance();
            if( $submission ) {
                $data = $submission->get_posted_data();
                if ( empty( $data ) )
                    return;
    
                $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><HotelReservations></HotelReservations>');
                $reservation = $xml->addChild('HotelReservation' );
                $reservation->addAttribute('Version', '2.1');
                $reservation->addAttribute('ResType', 'Request');
    
                $globalinfo = $reservation->addChild('ResGlobalInfo'); // Group Global Info
    
                $globalinfo->addChild('BookingDateTime', date('Y-m-d') . 'T' . current_time('G:i')); // Booking Date
                $globalinfo->addChild('ArrivalDate', date('Y-m-d', strtotime($data['datum-1']))); // Arrival
                $globalinfo->addChild('DepartureDate', date('Y-m-d', strtotime($data['datum-2']))); // Departure
    
                $guestcount = $globalinfo->addChild('GuestCounts'); // Group GuestCounts
    
                $adultcount = $guestcount->addChild('GuestCount'); // GustCount Adults
                $adultcount->addAttribute('Type', 'Adult'); // Type (Adults)
                $adultcount->addAttribute('Qty', $data['erw']); // Quantity Adults
    
                // Age of children (only when set)
                if ($data['kin'] > 0) {
                    $childage = $guestcount->addChild('GuestCount');
                    $childage->addAttribute('Age', $data['alt-1ki-1'] . $data['alt-2ki-1'] . $data['alt-3ki-1'] . $data['alt-4ki-1'] . $data['alt-5ki-1']);
                    $childage->addAttribute('Type', 'Child');
                }
    
                if ($data['kin'] > 1) {
                    $childage = $guestcount->addChild('GuestCount');
                    $childage->addAttribute('Age', $data['alt-2ki-2'] . $data['alt-3ki-2'] . $data['alt-4ki-2'] . $data['alt-5ki-2']);
                    $childage->addAttribute('Type', 'Child');
                }
    
                if ($data['kin'] > 2) {
                    $childage = $guestcount->addChild('GuestCount');
                    $childage->addAttribute('Age', $data['alt-3ki-3'] . $data['alt-4ki-3'] . $data['alt-5ki-3']);
                    $childage->addAttribute('Type', 'Child');
                }
    
                if ($data['kin'] > 3) {
                    $childage = $guestcount->addChild('GuestCount');
                    $childage->addAttribute('Age', $data['alt-4ki-4'] . $data['alt-5ki-4']);
                    $childage->addAttribute('Type', 'Child');
                }
    
                if ($data['kin'] > 4) {
                    $childage = $guestcount->addChild('GuestCount');
                    $childage->addAttribute('Age', $data['alt-5ki-5']);
                    $childage->addAttribute('Type', 'Child');
                }
    
                $guest = $reservation->addChild('Guest'); // Group Gust
    
                $guest->addChild('Salutation', $data['anr']); // Salutation
                $guest->addChild('FirstName', $data['vnam']); // First Name
                $guest->addChild('Surname', $data['nnam']); // Surname
                if($data['str']) {
                    $guest->addChild('Street', $data['str']); // street
                }
                if($data['plz']) {
                    $guest->addChild('ZipCode', $data['plz']); // Zip-Code
                }
                if($data['ort']) {
                    $guest->addChild('CityName', $data['ort']); // City
                }
                if($data['land']) {
                    $guest->addChild('State', $data['land']); // Country
                }
                $guest->addChild('Email', $data['mail']); // Mail
                if($data['tel']) {
                    $guest->addChild('Phone', $data['tel']); // Phone
                }
    
                Header('Content-type: text/xml');
                $xml->saveXML( 'anfrage.xml' );
    
                $mail = $instance->prop('mail');
                $mail['additional_headers'] = "Cc: [email protected]";
                $instance->set_properties( array(
                    'mail' => $mail
                ) );
    
                $submission->add_uploaded_file( 'submission_xml', 'anfrage.xml' );
                return $instance;
            }
        }
    }

    I tried to solve the problem with the help of similar posts, but was not successful.
    https://www.ads-software.com/support/topic/private-add_uploaded_file/
    https://positionabsolute.de/blog/creating-an-xml-file-from-a-contactform7-submission

    Please help me to solve this problem without changing the way it works.

    Thank you in advance for your help!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem with attach created XML file from a submission’ is closed to new replies.