WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
no documentation for developers? (15 posts)

  1. Naoise Golden Santos
    Member
    Posted 3 years ago #

    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?

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

  2. Naoise Golden Santos
    Member
    Posted 3 years ago #

    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

  3. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    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.

  4. Naoise Golden Santos
    Member
    Posted 3 years ago #

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

  5. mishals
    Member
    Posted 3 years ago #

    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);
  6. Naoise Golden Santos
    Member
    Posted 3 years ago #

    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.

  7. vinceMonarchy
    Member
    Posted 3 years ago #

    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 ?>" />

  8. Naoise Golden Santos
    Member
    Posted 3 years ago #

    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!

  9. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

  10. vinceMonarchy
    Member
    Posted 3 years ago #

    Perfect thank you!

  11. maorb
    Member
    Posted 3 years ago #

    These mail tags are great - didn't know they exist, really helpful, thanks.

  12. aravindajith
    Member
    Posted 3 years ago #

    Found a better solution here -> http://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]

  13. progresst
    Member
    Posted 3 years ago #

    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?

  14. halfacat
    Member
    Posted 3 years ago #

    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?

  15. Karesansui
    Member
    Posted 3 years ago #

    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,

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic