• This is a good and simple plugin but it is too simple.

    First I am unable to find a proper documentation for make more sophisticated things.

    It has a lot of potential to empower other developers to make add-ons to the plugin, but there is no centralized site where we can find those add-ons?

    In my case I am implementing a new tag to know the URL of the page where the form is sent from and I just can’t find the wpcf7_add_shortcode function reference.

    any help on this matter?

    https://www.ads-software.com/extend/plugins/contact-form-7/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter Naoise Golden Santos

    (@ngolden)

    I finally got a working code:

    function hiddenreferer_shortcode($tag) {
    
    	if ( ! is_array( $tag ) )
    		return '';
    
    	$options = (array) $tag['options'];
    	foreach ( $options as $option ) {
    		if ( preg_match( '%^name:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
    			$name_att = $matches[1];
    		}
    	}
    
    	 $pageURL = 'http';
    	 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    	 $pageURL .= "://";
    	 if ($_SERVER["SERVER_PORT"] != "80") {
    	  	$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    	 } else {
    	  	$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    	 }
    
    	 $value_att = $pageURL;
    	 $html = '<input type="hidden" name="' . $name_att . '" value="'.$value_att.'" />';
    	 return $html;
    }
    wpcf7_add_shortcode('hiddenreferer', 'hiddenreferer_shortcode', true);

    usage:

    //use [hiddenreferer referer name:referer] in the form
    //and [referer] in the email template

    Ir can probably be done better (less code, more poetry).
    I don’t know why the duplicity of referer name:referer is needed but it works like this…

    If someone comes up with a nicer code please share.

    bazinga

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    you can get the name by $name_att = $tag['name'], them you don’t need name:referer option any more.

    sorry for the poor documentation for add-on development, I’m writting it right now.

    Thread Starter Naoise Golden Santos

    (@ngolden)

    Neat. Thank you Takayuki. Good luck with the documentation, and thank you for your time and this nice plugin ??

    Thank you for this referer & info
    But which file edit for add this code ?

    function hiddenreferer_shortcode($tag) {
    
        if ( ! is_array( $tag ) )
            return '';
    
        $options = (array) $tag['options'];
        foreach ( $options as $option ) {
            if ( preg_match( '%^name:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
                $name_att = $matches[1];
            }
        }
    
         $pageURL = 'http';
         if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
         $pageURL .= "://";
         if ($_SERVER["SERVER_PORT"] != "80") {
              $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
         } else {
              $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
         }
    
         $value_att = $pageURL;
         $html = '<input type="hidden" name="' . $name_att . '" value="'.$value_att.'" />';
         return $html;
    }
    wpcf7_add_shortcode('hiddenreferer', 'hiddenreferer_shortcode', true);

    Thread Starter Naoise Golden Santos

    (@ngolden)

    This would go in your /wp-content/themes/theme-name/functions.php file, so when you update the plugin the code doesn’t disappear.

    Never hack the code of plugins. Also I recommend using child themes before changing any code on a theme.

    is there a way to get IP address and User Agent too? Can the following code be added somewhere to do achieve this?

    <?php
    $ipi = getenv(“REMOTE_ADDR”);
    $httprefi = getenv (“HTTP_REFERER”);
    $httpagenti = getenv (“HTTP_USER_AGENT”);
    ?>

    <input type=”hidden” name=”ip” value=”<?php echo $ipi ?>” />
    <input type=”hidden” name=”httpref” value=”<?php echo $httprefi ?>” />
    <input type=”hidden” name=”httpagent” value=”<?php echo $httpagenti ?>” />

    Thread Starter Naoise Golden Santos

    (@ngolden)

    As far as I know:
    Sender’s IP address: [wpcf7.remote_ip]

    That is a built-in tag you put in the mail template (right box). Let’s hope Takayuki Miyoshi’s documentation reveals all the tags that are at our disposal!

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    Perfect thank you!

    These mail tags are great – didn’t know they exist, really helpful, thanks.

    Found a better solution here -> https://tonykwon.com/2010/09/can-we-capture-http-referer-information-upon-form-submission-using-contact-form-7/

    1. Add a Text Field element with a css class referer-page
    [text referer-page class:referer-page]

    2. Add the following css to your styles.css
    input.referer-page { display:none; }

    3. Add the following code snippets to your functions.php?

    function getRefererPage( $form_tag )
    {
            if ( $form_tag['name'] == 'referer-page' ) {
                    $form_tag['values'][] = $_SERVER['HTTP_REFERER'];
            }
            return $form_tag;
    }
    if ( !is_admin() ) {
            add_filter( 'wpcf7_form_tag', 'getRefererPage' );
    }

    4. Add the following to the Contact Form 7 Message body (under Mail)

    Referer Page: [referer-page]

    I am using the do_shortcode like this:

    <?php echo do_shortcode( '[contact-form 1 "Contact form 1"]' ); ?>

    How do I specify the subject from this, can I do that?

    Hi,

    I want to capture info about what keyword they searched a Google to find and fill the form. It would be really cool to also capture my AdWords data like Salesforce’s webforms do.

    Does anyone know of a way to do this using CF7?

    Well that hardly sounds like a CF7 extension to me.

    In Google Analytics you can see the source and keywords used to get to a page (or form). You can also relate a page (and form) to a campaign.
    I thank that is the place to look for such a solution.
    And you can also connect AdWords to Analytics… and you can set a form page as a target …. all in Google.

    Enjoy,

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Plugin: Contact Form 7] no documentation for developers?’ is closed to new replies.