Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter moviemaniac

    (@moviemaniac)

    No, unfortunately I am afraid that doing so could break my website.

    Thread Starter moviemaniac

    (@moviemaniac)

    HI and thanks for repling.
    I’ve uninstalled wpide 2.5, downloaded v.2.4 and uploaded it to my webserver, then I activated it through wp plugins page.

    Well, nothing has changed, WPIde does not show up in the left panel in my administration area.

    Could someone esplain how to fix this?
    Again, I am running WP 5.1.1 + WPIde 2.4
    Thanks

    Thread Starter moviemaniac

    (@moviemaniac)

    Time is not on my side, unfortunately. So I had to go on and try to understand how to fix things.
    I came out with this solution, after a bit of trial and error, it is not the best one obvioulsy, but it is working as expected. I beg the author of the plugin to please give a bit of support on this. I do not want to mislead anyone.

    The below filter looks at the form id and acts consequently. I have a form with three options (checkboxes) which the submitter can choose alternatively. And then I need to send out an email in two cases out of three (need not to send it for a given option), plus I have several other forms for which I do not have to send out email at all.

    /**
    * $skip_mail is true or false, tells whether to send email or not 
    * $wpcf7 is the current form template (not the data sent through it!!!)
    */
    function mycustom_wpcf7_skip_mail( $skip_mail, $wpcf7 ) {
    	if (( ID1==$wpcf7->id() ) || ( ID2==$wpcf7->id() )) {
    		return true;
    	}
    	
    	if ( ID3 == $wpcf7->id() ) {
    		// redirect after the form has been submitted
            $wpcf7->set_properties( array(
                'additional_settings' => "on_sent_ok: \"location.replace('http://ID3-REDIRECT//');\"",
            ) );
    	}
    
    	//	[.....]
    	
    	if ( IDN != $wpcf7->id() ) {
    		return true;
    	}
    	
    	/*
    	    $instance = WPCF7_Submission::get_instance();
            $posted_data = $instance->get_posted_data();
    		** The above two lines of code are equivalent to the following line, but more readable
    	*/
    	
        $posted_data = WPCF7_Submission::get_instance()->get_posted_data("MYITEM");
    
    	if($posted_data[0]==='MYITEM SPECIAL CONTENT NOT TO MAIL TO') {
    		return true;
    	}
    	return $skip_mail = false;
    }
    add_filter( 'wpcf7_skip_mail', 'mycustom_wpcf7_skip_mail', 10, 2 );
    moviemaniac

    (@moviemaniac)

    Found this post very useful. I had a piece of code that, after upgrading my website to the latest wp/wpcf7 (was still using wp<4 and old wpcf7) wasn’t working anymore.

    This was the doce:

    function my_custom_emailing( $wpcf7 ) {
    	$myStr = array('plant1' => "email1",
    				   'plantN'	=> 'mailM');
    	if (( $wpcf7->id == XXX ) || ( $wpcf7->id == YYY )) {
    		$wpcf7->skip_mail = 1;
    	}
    	if ( $wpcf7->id == ZZZ ) {
    		wp_redirect( 'http://mysampleredirect' );
    		$wpcf7->skip_mail = 1;
    	}
    	if ( $wpcf7->id != MYSPECIAL ) {
    		return $wpcf7;
    	}
    	if ( $wpcf7->id == MYSPECIAL ) {
    		if ( $wpcf7->posted_data ) {
    			if($wpcf7->posted_data['Item'][0]==='Register') {
    				$wpcf7->skip_mail = 1;
    			}
    			if($wpcf7->posted_data['Item'][0]==='TVCC') {
    	$wpcf7->posted_data['email_to']=$myStr[$wpcf7->posted_data['plant']];
    				$wpcf7->posted_data['email_cc'] = 'my, custom, cc, comma, separated';
    			}
    	
    			if($wpcf7->posted_data['Item'][0]==='Maintenance') {
    				$wpcf7->posted_data['email_to'] = "custom_to@domain.com";
    				$wpcf7->posted_data['email_cc'] = "custom_cc@domain.com";
    			}
    		}
    		return $wpcf7;
    	 }
    }
    add_action( 'wpcf7_before_send_mail', 'my_custom_emailing');

    After reading this post, I changed my piece of code this way

    function my_custom_emailing( $wpcf7 ) {
    	if (( XXX==$wpcf7->id ) || ( YYY==$wpcf7->id )) {
    		$wpcf7->skip_mail = 1;
    	}
    	if ( ZZZ == $wpcf7->id ) {
    		wp_redirect( 'http://mysampleredirect' );
    		$wpcf7->skip_mail = 1;
    	}
    	if ( MYSPECIAL != $wpcf7->id ) {
    		return $wpcf7;
    	}
    	if ( MYSPECIAL == $wpcf7->id ) {
    		if ( $wpcf7->posted_data ) {
    			if($wpcf7->posted_data['Item'][0]==='Register') {
    				$wpcf7->skip_mail = 1;
    			}
    		}
    		return $wpcf7;
    	 }
    }
    add_action( 'wpcf7_before_send_mail', 'my_custom_emailing');
    
    function set_question_form_recipient($components, $form, $object) {
    
      if (XXX == $form->id()) {
    
    	$myStr = array('plant1' => "custom@domain.com",
    				   'plantX' => "sample@mail.net"
    				   );
    
    	$submission = WPCF7_Submission::get_instance();
        $posted_data = $submission->get_posted_data();
    
    	if($posted_data['Item'][0]==='TVCC') {
    	  $components['recipient'] = $myStr[$posted_data['plant']];
    	  $components['additional_headers'] = 'CC: my, custom, cc, comma, separated';
    	}
    	  
    	if($posted_data['Item'][0]==='Maintenance') {
    	  $components['recipient'] = 'customrecipient@sample.net';
    	  $components['additional_headers'] = 'CC: custom_cc@sample.net';
    	}
      }
      
      // Return the modified array (not sure if needed)
      return $components;
    }
    add_filter('wpcf7_mail_components', 'set_question_form_recipient', 10, 3);

    Well, to be honest at least it works, in the sense that emails are being sent once again when needed. But in a particular condition, when mail should be skipped, I receive the standard errr message complaining that there was an error while sending the email.
    This should be due to the recipient not being set up, but I do not need to send the email so no recipient…

    I believe that the error is due to the skip_email not working as expected.

    Anyone could point me to the right direction?

    Thanks

    Thread Starter moviemaniac

    (@moviemaniac)

    Hi Michael,
    I knew I was getting lost in a glass of water. Counldn’t you see the air bubbles going up? 😀
    Thanks for pointing me out to the solution.
    I’ve changed the action of the second form to “$_GET”, and then I am recalling it via url like follows

    href="test_page/?Plant=pname&month=02&year=2014&x=1"

    now it works like a charm.

    There is just one problem left, which I believe has nothing to do with cfdb, but I ask just in case you can help…

    Given that AFAIK is not possible to use an url with parameters to call a page and then access those parameters via $_POST, when I access the child page I get the url in the address bar of the browser with all the parameters, which is everything but friendly.
    Could it be possible to have a kind of rewritten rule instead of the raw url?

    For example, could it be possible to have the former link written like follows

    http://www.my_website.com/test_page/Plant/pname/month/02/year/2014/x/1
    or even better
    http://www.my_website.com/test_page/pname/02/2014/1

    Thanks a lot for your help and for your awesome module!

    P.S. It seems that the fix to the “new lines” in json output problem is working properly! 😉

Viewing 5 replies - 1 through 5 (of 5 total)