• Resolved SilverKenn

    (@kosher_12)


    I have a custom code implemented on submit function, where after the user put their email and select dropdown menu and submit.
    they will recieve an email corresponding to what they choose on the dropdown.

    My problem is I have only used 1 form on 5 different Page, and I would like to add additional code to determine in what page is the form submitted before taking action.

    Here’s my code that determine based on user selection.

    add_action( 'wpcf7_before_send_mail', 'different_autoresponder_message' );
    function different_autoresponder_message( $cf7 ) {
    	//check if this is the right form
    	if ($cf7->id==635){
     		//Do Something Here
    
    		//Spacing for additional Messages
    		if ($cf7->mail['use_html']==true)
    			$nl="<br/>";
    		else
    			$nl="\n";
    
    		//Set Message Depending on User Selection
    		if($_POST['menu-689'] == '1 Day Course') {
    					$message=$nl.$nl.'1 Day Course'.$nl;
     					$message.='Thank For your Download..'.$nl;
    		}
    		else {
    			$message=$nl.$nl.'User Dont want it'.$nl;
    			$message.='No more Download..'.$nl;
    		}
    
    		$cf7->mail_2['body'].=$message;
    
    	}
    }

    Its working properly,
    However, since the form is used more than 3 times.

    I’d also like to changed the message based on what Page is the form.

    so In short, I have two action to determine before form submission. first is based on the user Selection on the form dropdown(which I already achieved). and second is in what page is the form.

    I’ve tried adding if is_page statement on the code but its not working,

    Something like this.

    //Set Message Depending on User Selection
    		if (is_page(1455))  {
    				if($_POST['menu-689'] == '1 Day Course') {
    							$message=$nl.$nl.'1 Day Course'.$nl;
    							$message.='Thank For your Download..'.$nl;
    				}
    				else {
    					$message=$nl.$nl.'User Dont want it'.$nl;
    					$message.='No more Download..'.$nl;
    				}
    
    		}
    		else {
    			// Do Something....
    		}

    Can anybody help?

    Much Appreciated..

    Regards,
    Kenn

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    You can get post ID by using a special mail tag ‘[_post_id]’ in mail content. Looking into how it gets the post ID in modules/special-mail-tags.php would help.

    Thread Starter SilverKenn

    (@kosher_12)

    Thanks for you response.

    I really appreciate it.

    However, I am really new in PHP and that’s what I am trying to achieve but no success, I’ve been digging on cf7 plugin files, but really confuse how [_post_id] works.

    i see this line

    if ( ! isset( $_POST['_wpcf7_unit_tag'] ) || empty( $_POST['_wpcf7_unit_tag'] ) )
    		return $output;
    
    	if ( ! preg_match( '/^wpcf7-f(\d+)-p(\d+)-o(\d+)$/', $_POST['_wpcf7_unit_tag'], $matches ) )
    		return $output;
    
    	$post_id = (int) $matches[2];
    
    	if ( ! $post = get_post( $post_id ) )
    		return $output;

    on special-mail-tags.php but having a hard time implementing it on my current code.

    I would be very thankful if you could help me though.

    Kenn

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Contact Form 7 if on the Specific Page.. Do something.’ is closed to new replies.