WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
Controlling the send to option (5 posts)

  1. nims
    Member
    Posted 1 year ago #

    I want to control the "send to" option of the contact form 7 depending on the logged in status of the user.

    I want, if the user is signed in and filling the contact form then the form should be sent to a@mysite.com and if the user is filling the form and not signed in then the form should be sent to b@mysite.com

    Please let me know how can this be done. I can do moderate PHP coding. Thanks.

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

  2. biswajeet
    Member
    Posted 1 year ago #

    At most simplest, you can do the following -

    Create two contact form - 1) for Logged in user and 2) for other user. Make the necessary respective setting for the forms and use login conditional check to display the proper form to the visitors.

  3. Ov3rfly
    Member
    Posted 1 year ago #

    If you can do moderate PHP coding, there is a way, but it includes changing a file of the plugin, so if you ever update the plugin, you have to include this change again.

    1. Set the "send to" of your form to b@mysite.com (default: not logged in)

    2. Make a backup copy of plugin file contact-form-7/includes/classes.php in case something goes wrong.

    3. In plugin file contact-form-7/includes/classes.php at around line 500 locate this:

    $recipient = $this->replace_mail_tags( $mail_template['recipient'] );

    4. Add a new line of code so it looks like this:

    $recipient = $this->replace_mail_tags( $mail_template['recipient'] );
    $recipient = apply_filters( 'ov3rfly_wpcf7_change_recipient', $recipient );

    5. Then in your themes function.php add this:

    function my_change_recipient( $recipient ) {
    	if ( is_user_logged_in() ) {
    		$recipient = 'a@mysite.com';
    	}
    	return $recipient;
    }
    add_filter( 'ov3rfly_wpcf7_change_recipient', 'my_change_recipient' );
  4. nims
    Member
    Posted 1 year ago #

    @Ov3rfly I dont think changing the core plugin files is a good idea.

    @biswajeet Thanks for the hint. Would try that.

    If anyone has a better solution, pls share.

  5. Ov3rfly
    Member
    Posted 1 year ago #

    Oh, actually there is a much easier way, I just did not see the filter-call in the plugin earlier, I only looked for apply_filters() and not for apply_filters_ref_array()...

    No changes in plugin required, just use this:

    1. Set the "send to" of your form to b@mysite.com (default: not logged in)

    2. Then in your themes function.php add this:

    function my_wpcf7_mail_components( $arr, $this = '' ) {
    	if ( is_user_logged_in() ) {
    		$arr['recipient'] = 'a@mysite.com';
    	}
    	return $arr;
    }
    add_filter( 'wpcf7_mail_components', 'my_wpcf7_mail_components' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.