• Resolved batman42ca

    (@batman42ca)


    Is there any way I can get a ContactForm7 form, to simply POST the form information to a page of my choosing?

    I know how to stop it from sending the email.

    $cf7 = WPCF7_ContactForm::get_current();
    $cf7->skipMail = true;

    I know how to disable Ajax.

    define( 'WPCF7_LOAD_JS', false );

    I know how to redirect the form.

    add_filter( "wpcf7_form_action_url","redirectCf7");
    function redirectCf7 ($url) {
     $cf7 = WPCF7_ContactForm::get_current();
     return("http://mywebsite/myOwnPage/");
    }

    … but when the browser arrives at my designated page, $_POST is empty. If I can gain access to $_POST, I can use ContactForm7 for something more than sending email.

    https://ww.wp.xz.cn/plugins/contact-form-7/

Viewing 1 replies (of 1 total)
  • Thread Starter batman42ca

    (@batman42ca)

    I finally have a solution that works. The basics of the code is as follows. In my custom functions.php file:

    // ensure a session is started even if running via an AJAX call.
    if (!session_id()) {
      session_start();
    }
    
    function interceptCf7 ($cf7Form) {
      $cf7 = WPCF7_ContactForm::get_current();
    
      $submission = WPCF7_Submission::get_instance();
    
      // if a form was submitted
      if ( $submission ) {
        $_SESSION[cf7Data] = $submission->get_posted_data();
      }
      // don't send the email
      $cf7->skip_mail = true;
    }
    add_action("wpcf7_before_send_mail", "interceptCf7");

    I also configure the extra settings in my form admin with this:

    on_sent_ok: "location = 'http://myWebSite/myPage';"

    With that, I have access to he form data so I can do whatever I want with it. Submit it to a database, display in on the web page, pre-fill a PayPal form, whatever.

    I had tried using $_SESSION earlier, but it failed because I called session_start() in header.php, but header.php is not going to be included during an AJAX call. Realizing that, and adding another session_start() call where my custom functions exists so that during AJAX call, a session will be started, gave me access to the data that I wanted in the way that I wanted it.

    NOTE that the above code would be applied to ALL contactForm7 forms. I haven’t tested it yet but I believe it may be possible to check one of the following variables to test if the desired form is the one being processed (placed inside my “interceptCf7 function above”)

    $cf7 = WPCF7_ContactForm::get_current();
    
    // check one of these to see if it matches the desired form
    $cf7->id // ex: 867
    $cf7->name // ex contact-form-1
    $cfg7->title // ex Contact form 1

    Hopefully this helps someone else.

Viewing 1 replies (of 1 total)

The topic ‘capture $_POST?’ is closed to new replies.