WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
Use CF7 with action another WP page?? (12 posts)

  1. DDT
    Member
    Posted 2 years ago #

    Hi

    I like to have a very simple form action like so

    <form id="form1" name="form1" method="post" action="step1">
      <label>Code
      <input type="text" name="code" />
      </label>
    </form>

    Can this also be done with CF7?

    regards

    ps: Step1 is a page with a CF7 form.

  2. DDT
    Member
    Posted 2 years ago #

    and i like the CF7 form in step1 to have an action to step2 which is another CF7 form and now the data is being sent to Email and DB??

  3. Oleg Dudkin
    Member
    Posted 2 years ago #

    Hi
    There is an action - wpcf7_before_send_mail.
    It gives you control over whole form object.
    You can store posted_data property to session and then prevent from sending email for step1.
    on_sent_ok: must be set to redirect to step2.
    When you catch step2 form add data from first form to it.
    Hope it helps.
    Don't know the way to do it without PHP coding.

  4. DDT
    Member
    Posted 2 years ago #

    hi Oleg,

    Tx for your answer, i think you are pointing me in the right direction.
    But it seems the session part isn't working.

    Email is being sent

    What i have done is:

    1/ added the following to CF additional settings
    on_sent_ok: "location = '/step-2/';"

    2/ added this to functions.php

    function storeDataStep1($cf7) {
    
    	session_start();
    	$_SESSION['firstname'] = $cf7->posted_data["your-firstname"];
    	$_SESSION['lastname'] = $cf7->posted_data["your-lastname"];
    	$_SESSION['company'] = $cf7->posted_data["your-company"];
    	$_SESSION['address'] = $cf7->posted_data["your-address"];
    	$_SESSION['zip'] = $cf7->posted_data["your-zip"];
    	$_SESSION['city'] = $cf7->posted_data["your-city"];
    	$_SESSION['country'] = $cf7->posted_data["your-country"];
    	$_SESSION['email'] = $cf7->posted_data["your-email"];
    }
    
    add_action( 'wpcf7_before_send_mail', 'storeDataStep1' );

    3/Now in the step 2 template i check for session but it returns nothing

    if(is_page(29)) {
    		//step2
    		echo "Session Values";
    		echo $cf7->posted_data["your-firstname"];
    		echo $_SESSION['firstname'];
    		die();

    ps: how can is change the default message in CF form 1 to "Now we go to step 2" instead of "Your message was sent etc"

  5. Oleg Dudkin
    Member
    Posted 2 years ago #

    session_start();
    Should be at the very top of functions.php
    Instead:
    on_sent_ok: "location = '/step-2/';"
    Try :
    on_sent_ok: "location.replace('http://www.xxx.yyy/step-2/');"

    function storeDataStep1($cf7) {
    Use
    function storeDataStep1( &$cf7 ) {

    To prevent email sending:
    $cf7->skip_mail = true;

    To change message:
    Unfold "Messages" metabox in WP admin when editing form.

  6. Oleg Dudkin
    Member
    Posted 2 years ago #

    And one more sing:
    Check $cf7->id when saving form data. storeDataStep1($cf7) is called for both Step1 and Step2

  7. DDT
    Member
    Posted 2 years ago #

    hi oleg,

    You help me a lot i am almost there but now the email isn't done at all. The db insert does work
    I do get

    Your message was sent successfully. Thanks.

    is $cf7->skip_mail = true; a global setting??

    Will post the process if it works.

  8. DDT
    Member
    Posted 2 years ago #

    couple of things

    1/ email not being sent
    i think it's because i have
    add_action( 'wpcf7_before_send_mail', 'storeDataStep1' );
    which wil be triggered by both forms, right?

    2/ values are inserted twice for form 1 and form 2

    3/ on_sent_ok: location seems to be slow???

    i use the to-database-extension is there something which prevent form 1 values to be inserted (just like skip_mail??)

    in functions.php i have
    [Code moderated as per the Forum Rules. Please use the pastebin]

    and in child theme header.php
    [Code moderated as per the Forum Rules. Please use the pastebin]

  9. Oleg Dudkin
    Member
    Posted 2 years ago #

    $cf7->skip_mail = true; should be set only for step1 form.

    Replace is slow. It is loaded through ajax, then message is shown, and then replace is executed.

    There are field for skipping some form in database options. You need to fill form name, and step1 form data won't be saved to DB.

    Don't forget to clean $_SESSION after form2 is sent.

  10. Oleg Dudkin
    Member
    Posted 2 years ago #

    One more momemt,
    when you add action wpcf7_before_send_mail, specify priority lower than 10, to process form before DB extension - it uses the same hook

  11. viniciuscamara
    Member
    Posted 2 years ago #

    Hello there, congratulations form explanation.
    I'd one more question.
    Can I get more values at $cf7 var ? Like form-action or name of form ?
    Thanks.

  12. candy2012
    Member
    Posted 1 year ago #

    for the "smart" ones who killed the codes above as per I dont know which funny forum rules, if they are not capable themselves to offer any kind of constructive help, they should at least let the ones who DO, provide the full information.

    And if you really had even 1 gramm of intention to provide ANY help, you would have pasted the code to that pastbin yourself, and linked to it (serving also as example" for "how to do it")

    Like this, not only are you uncapable to provide any kind of assistance, but you actually do HARM and block important information from people who DID take the time to try to contribute something!

    Wish such so-called "Moderators" will be banned for ever and ever and never allowed to moderate a thing!

    Do harm is always 1000000000 times easier than providing some help, isn't it "moderators" !?!?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic