WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
wpcf7_mail_sent infinite loop (9 posts)

  1. frOst_EntAngLE
    Member
    Posted 1 year ago #

    I created a couple of functions to trigger once the contact form is sent. This function generates a unique reference number and saves it on a database table together with a couple of posted data. The form successfully sends a mail and a database row is also added successfully however there is a weird occurrence on the form page, it does not go past beyond the loading icon and does not show up the 'sent successfully' message. Aside from that, the page does not get redirected to the thank you page which I set using on_sent_ok.

    add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' );

    function gen_ref( $ref_name = 'X X') {
    $int_ren_name = split(" ",preg_replace('/\s\s+/', ' ', trim($ref_name)));
    $fname = strtoupper($int_ren_name[0]);
    $sname = (count($int_ren_name)>1) ? strtoupper($int_ren_name[1]) : $fname{1};

    return date("U").$fname{0}.$sname{0};
    }

    function your_wpcf7_mail_sent_function( $contact_form ) {
    global $wpdb;
    $title = $contact_form->title;
    $posted_data = $contact_form->posted_data;

    if ( 'Contact Us Form' == $title ) {
    $name = $posted_data['name'];
    $surname = $posted_data['surname'];
    $email = $posted_data['email'];
    $ref_name = $name." ".$surname;

    $referenceNumber = gen_ref($ref_name);

    $sql = $wpdb->prepare("INSERT INTO wp_formdata(reference_id, name, surname, email) VALUES (%d,%s,%s,%s)", $referenceNumber, $name, $surname, $email);

    $wpdb->query($sql);

    }
    }

    http://wordpress.org/extend/plugins/contact-form-7/

  2. biastechnology
    Member
    Posted 1 year ago #

    We are looking to do something very similar. Where did you place this code?

    Within the functions.php or within on_sent_ok: ""

    Technically we need to do it slightly differently:-

    Submit
    Insert Data into DB
    Return Index_ID
    Compile email with Index_ID
    Send Email
    Success Screen.

    I'll have a play this end and let you know how I got on

  3. frOst_EntAngLE
    Member
    Posted 1 year ago #

    I have it on functions.php. The process works fine, it sends the email and saves a row on the DB. However it could not get past the loading icon beside the button and display the success/failure message.

  4. biastechnology
    Member
    Posted 1 year ago #

    This may be of use:-

    How to: Redirect after submit

  5. frOst_EntAngLE
    Member
    Posted 1 year ago #

    That looks good, but that doesn't solve the issue. I know there is an issue because when I tested it before I made the changes above, the form first displays the usual green success notification that the email was sent and then it redirects the page to the page I set using on_sent_ok. The post you shared above would probably skip the green success message and just redirect to the page.

  6. frOst_EntAngLE
    Member
    Posted 1 year ago #

    Anyone else?

  7. HarrisITServices
    Member
    Posted 1 year ago #

    I am having the same issue and cannot figure it out. I have tried the following two snippets of code in functions.php and the email sends but the page never redirects. It just stays with the little spinning circle next to the submit button. If anyone has figured this out please let me know as this is driving me nuts.

    add_action('wpcf7_mail_sent', 'wpcf7_redirect_on_submit');
    function wpcf7_redirect_on_submit($wpcf7)
    {
    		wp_redirect( 'http://www.google.com' );
    		exit;
    }
    add_action('wpcf7_mail_sent', 'wpcf7_redirect_on_submit');
    function wpcf7_redirect_on_submit($wpcf7)
    {
    		header( 'Location: http://www.google.com' );
    		exit;
    }
  8. HarrisITServices
    Member
    Posted 1 year ago #

    Anyone have any ideas? The only solution I could find was to turn off ajax. However, for me this is not a solution. Does anyone know how to use the wpcf7 hook to redirect without turning ajax off?

  9. kg69design
    Member
    Posted 1 year ago #

    I suppose that we can't use "output" here like "echo", "header" etc.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.