• Hello,

    I am using the Contact form 7 plugin, and what I would like to do is have the default text for a input field, be generated via query string.

    So I would think that the code would look something like this:
    [text* postID “<?php echo $_GET[‘postid’];?>”]

    and the url would obviously end in ?postid=3

    But that causes the text fied on the page to crash. Any ideas how to accomplish this?

Viewing 15 replies - 16 through 30 (of 32 total)
  • I came up against this problem using Contact Form 7 – I needed to include a custom field value in the subject of the form. I added this simple fix to the file modules\text.php. First find this code at line 76 on:

    // Value
    	if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) && $wpcf7_contact_form->is_posted() ) {
    		if ( isset( $_POST['_wpcf7_mail_sent'] ) && $_POST['_wpcf7_mail_sent']['ok'] )
    			$value = '';
    		else
    			$value = stripslashes_deep( $_POST[$name] );
    	} else {
    		$value = isset( $values[0] ) ? $values[0] : '';
    	}

    I then added the following lines:

    if ( $name == 'your-subject' )
    	{
    		global $post;
    		$result = get_post_meta($post->ID, 'Reference', true);
    		$value = "Ref: " . $result ;
    	}

    My hack places the value of the Custom Field ‘Reference’ as the subject line, so when a user sends a contact form, it contains the reference number of the property they are looking at. If you want to use this with a different custom field, just change the name ‘Reference’ to the one you want.

    If you want to see it in action have a look at the site:

    https://www.nerja-holidayrentals.com/

    Hope this is of use to someone else.

    Hi Dibbit, I wanted to do the same but cannot get this to work. Do you paste that code directly after? or instead of? Im unsure. Thanks.

    Also I like the idea of being able to use a custom field to control the TO: field of the contact form, so I can have contact form 1 in my template file and set the agents email on a post for post basis using the custom meta box I create. Any ideas?

    In regards to making the fields hidden, just use css.

    [text crc_header id:crc_notification class:hidden "GET_crc"]

    …and then in the style.css file just add …

    .hidden {
         display:hidden;
         }

    Good call Skoskie, however what if the field is already hidden? have you played much with custom meta boxes yet?

    I tried following autotransport…

    but

    When sending this url to my formpage:
    https://mywebsite.dk/site/?page_id=881&Annonce-overskrift=Here is the text

    instead of writing the variable in my txt field i just get the text <?php echo $_GET[‘Annonce-overskrift’]; ?> written inside the text field.

    Anyone knows why?

    Any chance of getting this behavior rolled into the release code?

    Having to manually add this feature with every release is tiresome and counter productive to using 3rd party plugins.

    I’m trying to get the last part of the referring page url to show in the form that’s sent to admin so that the administrator has a good idea of what triggered off the contact request. I’m thinking of using either a cookie or http_referrer, though http_referrer is apparently not reliable and cookies of course can be turned off.

    Anyone been here before and got a better idea or a snippet of code that will save me some time?

    richarduk,
    I am after the same, please post your finding afterwards.

    Also,
    I learned you can use Gravity Forms + plugin from Yoast.com: https://yoast.com/gravity-forms-widget-extras/

    Same with Cforms 2, very powerful (and complicated) and free. Like Gravity Forms it has an option to do stuff with referrer data.

    https://www.deliciousdays.com/cforms-plugin/

    richarduk,
    thank you for that!

    i didn’t see any info specifically about how to implement referrer tracking. Do you know how to do that?

    It’s not well documented on the site but once installed there’s a ton of documentation within the plugin.

    On the plugin home page:

    API / Creating dynamic forms

    Do you require more flexibility in your forms? Then create and deploy forms at run-time. Mind you, to use this feature it requires basic and possibly more advanced PHP knowledge, examples you’ll find in the HELP! section of plugin admin pages.

    This will essentially allow you to pull data from an external source and feed it into your ad-hoc created form fields. I’ve deliberately not included any sort of external data administration, as everyone will have a different file or database table syntax. Any of the fields described in the HELP! section can be created at run-time and shown online. Minor drawback: this works only in non-Ajax mode.

    I’ve got nowhere. I post this in the hope someone might cast some light on it. This is to go either in functions.php or header.php
    Page(‘3’) is the contact page. Note that echoing things would show referring urls etc. nicely at the top of the page but stopped the contact form from submitting.

    <?php global $filename;
             if (is_page('3')) {
    if(!isset($HTTP_REFERER))
    {$referer = strtolower($_SERVER["HTTP_REFERER"]);
    //echo 'TESTING TESTING';
    //echo $referer;
    $url2 = $referer;
    $filename = basename($url2);
     //echo $filename;
    }
     } ?>

    Then, in classes.php in the plugin, right before the line

    return @wp_mail( $recipient, $subject, $body, $headers, $for_this_mail );

    I added this:

    $subject = $subject.$filename;

    Since that didn’t work, I removed the code from either header.php or functions.php and from classes.php and tried adding this instead :

    $filename = wp_get_referer();
    $subject = $subject.$filename;
    
    return @wp_mail( $recipient, $subject, $body, $headers, $for_this_mail );

    All the time my emails came back with the same damned referrer, whch was the name of the page the contact form was on i.e. contact.php

    Is functions.php loaded before plugins?

    If so, I can’t see why this didn’t work.

    @richarduk: That was a little OTT, don’t you think? A modlook tag and a discrete pointer towards the offending post is all that is normally needed.

    I have no idea what a modlook tag is ??

    I’ll google it now

    ‘modlook’ tag is described in the forum rules.

    D: Reporting threads
    To report a bad post, add a tag called ‘modlook’ to the thread. That feed is checked very regularly and we can zoom in on it.

    I added modlook to this thread.

    @esmi I thought richarduk wrote “SPAM” about summitdevelop’s last comment. Actually it looked like a spam.

Viewing 15 replies - 16 through 30 (of 32 total)
  • The topic ‘Contact Form 7 Input Fields Values as PHP Get-Viarables’ is closed to new replies.