WordPress.org

Forums

Contact Form 7 Dynamic Text Extension
[resolved] Setting default value for CF7_GET (3 posts)

  1. huskypup
    Member
    Posted 2 years ago #

    Hi,
    I have a form that uses CF7_GET to pass email recipient address via a link within the content. It all works well apart from when the form is accessed via the page menu, due to it being a direct link to the page without variables being passed through the URL.

    Is there a way to set a default recipient? The form short code I'm using is

    [dynamichidden email-recipient "CF7_GET key='email_recipient' obfuscate='on'"]

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

  2. sevenspark
    Member
    Plugin Author

    Posted 2 years ago #

    To do that I think you would want to write a custom version of the CF7_get shortcode and set a default if no value is set.

  3. huskypup
    Member
    Posted 2 years ago #

    Thanks for replying, it pointed me in the right direction.

    I'm afraid my PHP skills are not very good, but I managed to cobble this together if anyone is interested.

    This goes into your functions.php

    function cf7_get_feedback_form_sc($atts){
    	extract(shortcode_atts(array(
    		'key' => '',
    		'default' => 'email@address.com'
    	), $atts));
    
    	if(isset($_GET[$key]) and !empty($_GET[$key])) {
    		return $_GET[$key];
    	} else {
    		return $default;
    	}
    
    }
    
    add_shortcode('CF7_GET_feedback_form', 'cf7_get_feedback_form_sc');

    I then use this as the shortcode used in Contact Form 7

    [dynamichidden email-recipient id:email-recipient "CF7_GET_feedback_form key='email_recipient'"]

    Hopefully it's okay, but I'm happy for feedback.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic