Viewing 9 replies - 1 through 9 (of 9 total)
  • Hey receter,

    Can you upload/pastebin your code somewhere in the meantime?

    Thanks in advance!

    Thread Starter receter

    (@receter)

    This should do the trick:

    /**
    	 * Modifies the emails by replacing the conditionals [if field_name][/if]
    	 *
    	 * @param [Object] $cf7 the contanct form 7 object
    	 * @return void
    	 * @author Tobias Braner
    	 **/
    	public function before_send_mail($contact_form) {
      		$submission = WPCF7_Submission::get_instance();
    		if ( $submission ) {
    			$posted_data = $submission->get_posted_data();
    			$mail = $contact_form->prop('mail');
    			$mail2 = $contact_form->prop('mail2');
    			$mail_body = $mail['body'];
    			$mail2_body = $mail2['body'];
    			$mail['body'] = $this->process_conditions($mail_body, $posted_data);
    			$mail2['body'] = $this->process_conditions($mail2_body, $posted_data);
    			$contact_form->set_properties(array('mail' => $mail, 'mail2' => $mail2));
    		}
    	}
    
    	/**
    	 * Takes the wpcf7 object and replaces all conditions.
    	 *
    	 * @return void
    	 * @author Tobias Braner
    	 **/
    	private function process_conditions($mail_body, $posted_data) {
    		$updated_email_body = $mail_body;
    		$matches = array();
    		$num_matches = preg_match_all($this->regexp, $mail_body, $matches);
    		for ($i=0; $i < $num_matches; $i++) {
    			$expression = $matches[WPCF7MC_EXPRESSION][$i];
    			$variable = $matches[WPCF7MC_VARIABLE][$i];
    			$value = $matches[WPCF7MC_VALUE][$i];
    			if (empty($posted_data[$variable][0]) and array_key_exists($variable, $posted_data)) {
    				$updated_email_body = str_replace($expression, '', $updated_email_body);
    			} else {
    				$updated_email_body = str_replace($expression, $value, $updated_email_body);
    			}
    		}
    		return $updated_email_body;
    	}

    Dear receter,

    thank you very much for your quick reply. But, I’m not experienced enough to know what to do with that code. Is there a simple way for me to get this running? Could you provide a simple step-by-step instruction? How can I pay you for your efforts? Please feel free to contact me directly or post the information here for everybody to benefit from it.

    Thank you very much in advance.

    Thread Starter receter

    (@receter)

    There is just one very short file in the plugin folder (besides the readme.txt). Open it and replace the functions inside with the functions I sent you. If you need further assistance, my email address is my wordpress username at gmail com.

    Made a smal adjustment to @receter’s code to make the plugin work with mail(2) in CF7 Version 4.4

    mail2 > mail_2

    
    	 /**
    	 * Modifies the emails by replacing the conditionals [if field_name][/if]
    	 *
    	 * @param [Object] $cf7 the contanct form 7 object
    	 * @return void
    	 * @author Tobias Braner
    	 **/
    	public function before_send_mail($contact_form) {
      		$submission = WPCF7_Submission::get_instance();
    		if ( $submission ) {
    			$posted_data = $submission->get_posted_data();
    			$mail = $contact_form->prop('mail');
    			$mail_2 = $contact_form->prop('mail_2');
    			$mail_body = $mail['body'];
    			$mail_2_body = $mail_2['body'];
    			$mail['body'] = $this->process_conditions($mail_body, $posted_data);
    			$mail_2['body'] = $this->process_conditions($mail_2_body, $posted_data);
    			$contact_form->set_properties(array('mail' => $mail, 'mail_2' => $mail_2));
    		}
    	}
    • This reply was modified 7 years, 9 months ago by kim.oj.

    Hello guys,

    How can I check the checkbox if there is selected a specific option?

    Like:
    if[checkbox_id/name=”blue”]Selected color: blue[/if]
    if[checkbox_id/name=”green”]Selected color: green[/if]

    Hi,
    if you have this in your form

    [checkbox checkbox-961 "test 1" "test 2" "test 3"]

    Then you just need to write this in your mail

    [checkbox-961]

    If you want to print something in the form, I unfortunately don’t have a answer.

    Hello,

    I explained it wrong. Sorry about that.

    So basically I want that the e-mail should have a condition for additional informations(internal purpose) based of the selected checkboxes:

    if[checkbox_id/name=”test1”]Information: xyz[/if]
    if[checkbox_id/name=”test2”]Information: abc[/if]
    if[checkbox_id/name=”test3”]Information: cdf[/if]

    I couldn’t figure that one out with one input, so I made separately input fields for every question I wanted to check.

    Hope you find another answer!
    /Kim

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Fixed Plugin’ is closed to new replies.