Wordpress 2024: ContactForm7 sending user to a php page with POST values

33 Views Asked by At

I am new to wordpress but not to php programming. Yet I know very little of Javascript.

I am using wordpress 6.4.1 with theme twentytwentythree.

I have a form in ContactForm7 and I want to use it as a regular form, as in

form action="ww.php" method="post"

ww.php will collect the data and form a string that will be passed to WhatsappWeb using curl. This is because the people who will process the data want to get it by Whatsapp, not by mail

I did my searches. I modified functions.php in my theme this way:

add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url($url)
{
    global $post;
    $id_to_change = 1857;
    if($post->ID === $id_to_change)
        return 'https://[domain]/ww.php';
    else
        return $url;
}

apply_filters( 'wpcf7_load_js', '__return_false' );

it gives "form action="https://[domain]/ww.php" method="post">" but it does nothing, it just sends the mail

Then I did this in functions php

function ti_custom_javascript() {
    ?>
        <script>
          document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '1856' == event.detail.contactFormId ) {
    setTimeout( () => {
        location = 'https://[domain]/ww.php/';
    }, 3000 ); // Wait for 3 seconds to redirect.
    }
}, false );
        </script>
    <?php
}
add_action('wp_head', 'ti_custom_javascript');

(post ID is 1857, form ID is 1856)

This redirects the page but POST data is lost

I have read ways to keep POST data but I don't understand where to use them.

Thanks and forgive my bad English.

0

There are 0 best solutions below