• I wrote an extension to CF7 for email verification https://wordpress.org/plugins/contact-form-7-email-verification/

    With the updated code in CF7 it’s no longer working, so working out how to make it work again.

    First up, how do set $skip_mail = true; from my code now?

    Then, I see how to get the posted data and the properties. After verifying an email address, how do I then use these 2 objects (WPCF7_Submission::get_instance() and $contact_form->prop( ‘mail’ )) to submit the form as per usual?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    $skip_mail is now a private property, and there is no public function to alter it, so preventing the actual mailing this way is no longer possible. I did discover a work around by using the ‘wpcf7_mail_components’ filter. If your callback adds to the passed array like so before returning the modified array:
    $components['send'] = false;

    it has the effect of suppressing the actual mailing with no apparent ill effects. This is a real hack, the filter was not intended to be used this way, but it seems to work. You will want to find a way to alter the form messages posted after submission because currently the message indicates the form was sent successfully. You would want it to say something about checking email to verify the address instead.

    You can add messages with the ‘wpcf7_messages’ filter, but I’m not sure how to set the response to display the added message, it is a private property with no function to alter it (again!). The message ultimately is displayed using jQuery AFAICT, so adding your own jQuery to suppress the original message and display your message should be possible as long as your script runs after CF7’s.

    As for $contact_form->prop( 'mail' ), this method appears to only return a generic mail template, a filter is used to replace the generic with actual values, but CF7 does not appear to add this filter to make the method useful, so you need to rely on the submission object like so:

    $submission = WPCF7_Submission::get_instance();
        $posted_data = $submission->get_posted_data();
        $senders_email_address = $posted_data['your-email'];
        $senders_name = $posted_data['your-name'];

    I’m still not sure how you should be saving the data so that you can use CF7 to mail the data to the site admin once the email is verified, I’ll let you know if I discover anything.

    How you deal with attachments will need to be altered as well, but restoring basic functionality to your plugin should occur first. Good luck!

    Moderator bcworkz

    (@bcworkz)

    OK, I was a bit confused about what $contact_form->prop( 'mail' ) was giving us, as I’m not that familiar with actually using CF7. I got it now. (I hope)

    The mail properties give you the tags used for the form fields. You then use wpcf7_mail_replace_tags() to get the actual submitted values for those tags. Thus, instead of the above code (which works if you had previously gotten the tags somewhere, they cannot be hard coded as was done above), you should do something like this:

    // get tag data from mail properties
    $mail_tags = $wpcf7_form->prop('mail');
    // get field values from tags;
    $mail_fields = wpcf7_mail_replace_tags( $mail_tags );
    $senders_email_address = $mail_fields['sender'];
    $recipients_email_address = $mail_fields['recipient'];

    Sorry for any confusion.

    Thread Starter magician11

    (@magician11)

    Thanks! I got a lot further with your input.

    So it’s almost working again.

    Emails don’t get sent (good thing). The verification email gets sent out. On clicking that link the mailing process is re-initiated and something gets sent… but it looks like the CF7 object I’m saving only has the template and not the contents of the submission. So I need to probably save something else. The saved object looks like this..

    WPCF7_ContactForm Object
    (
        [id:WPCF7_ContactForm:private] => 35
        [name:WPCF7_ContactForm:private] => contact-form-1
        [title:WPCF7_ContactForm:private] => Test form with attachments
        [properties:WPCF7_ContactForm:private] => Array
            (
                [form] => <p>Your Name (required)<br />
        [text* your-name] </p>
    
    <p>Your Email (required)<br />
        [email* your-email] </p>
    
    <p>Subject<br />
        [text your-subject] </p>
    
    <p>Your Message<br />
        [textarea your-message] </p>
    
    <p>Optional attachment<br/>
    [file attachment]</p>
    
    <p>Optional attachment 2<br/>
    [file attachment2]</p>
    
    <p>[submit "Send"]</p>
                [mail] => Array
                    (
                        [subject] => [your-subject]
                        [sender] => [your-name] <[your-email]>
                        [body] => From: [your-name] <[your-email]>
    Subject: [your-subject]
    
    Message Body:
    [your-message]
    
    thank you!
                        [recipient] => support@andrewgolightly.com
                        [additional_headers] =>
                        [attachments] => [attachment] [attachment2]
                        [use_html] => 1
                    )
    
                [mail_2] => Array
                    (
                        [active] => 1
                        [subject] => [your-subject]
                        [sender] => [your-name] <[your-email]>
                        [body] => Thanks for your message.
    
    Here is what you sent us..
    
    [your-message]
                        [recipient] => [your-email]
                        [additional_headers] =>
                        [attachments] => [attachment] [attachment2]
                        [use_html] => 1
                    )
    
                [messages] => Array
                    (
                        [mail_sent_ok] => Your message was sent successfully. Thanks.
                        [mail_sent_ng] => Failed to send your message. Please try later or contact the administrator by another method.
                        [validation_error] => Validation errors occurred. Please confirm the fields and submit it again.
                        [spam] => Failed to send your message. Please try later or contact the administrator by another method.
                        [accept_terms] => Please accept the terms to proceed.
                        [invalid_required] => Please fill the required field.
                        [captcha_not_match] => Your entered code is incorrect.
                        [invalid_email] => Email address seems invalid.
                        [invalid_url] => URL seems invalid.
                        [invalid_tel] => Telephone number seems invalid.
                        [invalid_number] => Number format seems invalid.
                        [number_too_small] => This number is too small.
                        [number_too_large] => This number is too large.
                        [quiz_answer_not_correct] => Your answer is not correct.
                        [invalid_date] => Date format seems invalid.
                        [date_too_early] => This date is too early.
                        [date_too_late] => This date is too late.
                        [upload_failed] => Failed to upload file.
                        [upload_file_type_invalid] => This file type is not allowed.
                        [upload_file_too_large] => This file is too large.
                        [upload_failed_php_error] => Failed to upload file. Error occurred.
                    )
    
                [additional_settings] =>
            )
    
        [unit_tag:WPCF7_ContactForm:private] =>
        [responses_count:WPCF7_ContactForm:private] => 0
        [scanned_form_tags:WPCF7_ContactForm:private] => Array
            (
                [0] => Array
                    (
                        [type] => text*
                        [basetype] => text
                        [name] => your-name
                        [options] => Array
                            (
                            )
    
                        [raw_values] => Array
                            (
                            )
    
                        [values] => Array
                            (
                            )
    
                        [pipes] => WPCF7_Pipes Object
                            (
                                [pipes:WPCF7_Pipes:private] => Array
                                    (
                                    )
    
                            )
    
                        [labels] => Array
                            (
                            )
    
                        [attr] =>
                        [content] =>
                    )
    
                [1] => Array
                    (
                        [type] => email*
                        [basetype] => email
                        [name] => your-email
                        [options] => Array
                            (
                            )
    
                        [raw_values] => Array
                            (
                            )
    
                        [values] => Array
                            (
                            )
    
                        [pipes] => WPCF7_Pipes Object
                            (
                                [pipes:WPCF7_Pipes:private] => Array
                                    (
                                    )
    
                            )
    
                        [labels] => Array
                            (
                            )
    
                        [attr] =>
                        [content] =>
                    )
    
                [2] => Array
                    (
                        [type] => text
                        [basetype] => text
                        [name] => your-subject
                        [options] => Array
                            (
                            )
    
                        [raw_values] => Array
                            (
                            )
    
                        [values] => Array
                            (
                            )
    
                        [pipes] => WPCF7_Pipes Object
                            (
                                [pipes:WPCF7_Pipes:private] => Array
                                    (
                                    )
    
                            )
    
                        [labels] => Array
                            (
                            )
    
                        [attr] =>
                        [content] =>
                    )
    
                [3] => Array
                    (
                        [type] => textarea
                        [basetype] => textarea
                        [name] => your-message
                        [options] => Array
                            (
                            )
    
                        [raw_values] => Array
                            (
                            )
    
                        [values] => Array
                            (
                            )
    
                        [pipes] => WPCF7_Pipes Object
                            (
                                [pipes:WPCF7_Pipes:private] => Array
                                    (
                                    )
    
                            )
    
                        [labels] => Array
                            (
                            )
    
                        [attr] =>
                        [content] =>
                    )
    
                [4] => Array
                    (
                        [type] => file
                        [basetype] => file
                        [name] => attachment
                        [options] => Array
                            (
                            )
    
                        [raw_values] => Array
                            (
                            )
    
                        [values] => Array
                            (
                            )
    
                        [pipes] => WPCF7_Pipes Object
                            (
                                [pipes:WPCF7_Pipes:private] => Array
                                    (
                                    )
    
                            )
    
                        [labels] => Array
                            (
                            )
    
                        [attr] =>
                        [content] =>
                    )
    
                [5] => Array
                    (
                        [type] => file
                        [basetype] => file
                        [name] => attachment2
                        [options] => Array
                            (
                            )
    
                        [raw_values] => Array
                            (
                            )
    
                        [values] => Array
                            (
                            )
    
                        [pipes] => WPCF7_Pipes Object
                            (
                                [pipes:WPCF7_Pipes:private] => Array
                                    (
                                    )
    
                            )
    
                        [labels] => Array
                            (
                            )
    
                        [attr] =>
                        [content] =>
                    )
    
                [6] => Array
                    (
                        [type] => submit
                        [basetype] => submit
                        [name] =>
                        [options] => Array
                            (
                            )
    
                        [raw_values] => Array
                            (
                                [0] => Send
                            )
    
                        [values] => Array
                            (
                                [0] => Send
                            )
    
                        [pipes] => WPCF7_Pipes Object
                            (
                                [pipes:WPCF7_Pipes:private] => Array
                                    (
                                        [0] => WPCF7_Pipe Object
                                            (
                                                [before] => Send
                                                [after] => Send
                                            )
    
                                    )
    
                            )
    
                        [labels] => Array
                            (
                                [0] => Send
                            )
    
                        [attr] =>
                        [content] =>
                    )
    
            )
    
        [locale] => en_US
    )

    Probably also saving something like the result of wpcf7_mail_replace_tags( $mail_tags );

    Code updated on GitHub. One of the lines that needs updating is this one.

    Thanks for the insight!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how do I set the $skip_mail variable?’ is closed to new replies.