Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi wordpresschamp, I’m trying to achieve the same thing, did you find a solution?

    Thread Starter wordpresschamp

    (@wordpresschamp)

    No and I’m still looking. I found some code somewhere, but couldn’t figure out how to use it. Apparently, this is the answer we’re looking for.

    /*
    * requires a checkbox with the name “newsletter” in your CF7
    */
    function wpcf7_my_validate( $result, $tag ) {
    $type = $tag[‘type’];
    $name = $tag[‘name’];

    if ( ’ncf’_form == $name ) {
    $subscribe = isset($_POST[$name]);

    if(function_exists(‘mymail_subscribe’) && $subscribe){
    $email = $_POST[’email’];
    $userdata = array(
    ‘ncf_name_field’ => $_POST[‘firstname’],
    ‘ncf_email_field’ => $_POST[‘email’],
    );
    $listname = “newsletter-subscribers”;
    mymail_subscribe($email, $userdata, $listname);
    }
    }

    return $result;
    }
    add_filter( ‘wpcf7_validate_checkbox’, ‘wpcf7_my_validate’, 10, 2 );

    Hey, I found out that this code was written by the MyMail plugin author and to work it’s necessary to put it in functions.php.

    It’s important not to forget to add the “newsletter” checkbox to all CF7 forms applicable.

    I haven’t had the change to try it yet, if it works with you let me know.

    Cheers

    Thread Starter wordpresschamp

    (@wordpresschamp)

    Thanks.
    I still don’t get how to use the code.
    I understand to put it in functions.php, but is that for the theme or the plugins functions.php.
    And where in the file, beginning, end, certain section, before a specific line?
    Also, how do you edit the code to work with a specific form you created or a specific newsletter you created?
    It still seems so confusing. I tried playing around with it thinking of those questions, but was never able to get it working.
    ??

    Later this week i’ll have the opportunity to test it, I’ll let you know how it goes.

    Cheers

    Ok, I had a chance to try it and got it to work. Here’s what I did:

    – Edited the file wp-content\plugins\myMail\includes\functions.php and added this code to the bottom of the file, just above “?>”:

    /*
     * requires a checkbox with the the name "newsletter" in your CF7
    */
    function wpcf7_my_validate( $result, $tag ) {
    	$type = $tag['type'];
    	$name = $tag['name'];
    
    	if ( 'newsletter' == $name ) {
    		$subscribe = isset($_POST[$name]);
    
    		if(function_exists('mymail_subscribe') && $subscribe){
    			$email = $_POST['email'];
    			$userdata = array(
    				'firstname' => $_POST['firstname'],
    				'lastname' => $_POST['lastname'],
    				'company' => $_POST['company'],
    				'phone' => $_POST['phone'],
    			);
    			$listname = "YOUR LIST NAME HERE";
    			mymail_subscribe($email, $userdata, $listname);
    		}
    	}
    
    	return $result;
    }
    add_filter( 'wpcf7_validate_checkbox', 'wpcf7_my_validate', 10, 2 );

    – Then I added the following tag to the CF7 forms:

    [checkbox newsletter default:1 "Subscribe newsletter"]

    – Checked my CF7 label names to match those of MyMail fields (firstname, email, company, etc) – note that “company” and “phone” are my custom fields

    – Tested to see if it works

    And it was done.

    Hope it works for you, if you need any help let me know.

    Cheers

    Thread Starter wordpresschamp

    (@wordpresschamp)

    Awesome. Thanks ever so much! I will play around with it and try to get it working on my setup.

    Hey guys. I got it to add the email to a MyMail list, but now the CF7 form is not sending an email when i complete the form.

    I need it to do it original function (send me an email with the user input data) AND add that data to a MyMail list.

    Any help would be much appreciated.

    Thanks

    Additional info:

    The newsletter checkbox cannot be checked by default as per our laws.

    So I have a Yes/No option.

    If Yes is selected, the email is added to my list but NO email is sent to me.

    If No is selected, the email is added to my list AND email IS sent to me.

    Any way to fix this so it send me an email regardless of the choice and adds to the list only when yes is selected.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘CF7 adds email and name to MyMail list’ is closed to new replies.