• Casemon

    (@casemon)


    Have successfully embedded Custom Form 7 on various pages, and it’s great!

    Is there a means to including the page from which the form was submitted from in the email that is sent?

    Better, can I grab a custom field from the originating page and send that?

    Can think of how to do it in PHP, but cannot see how to get Custom Form 7 to process the PHP prior to sending.

    In any case, great plugin!

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

Viewing 15 replies - 1 through 15 (of 29 total)
  • Takayuki Miyoshi

    (@takayukister)

    bhomatude

    (@bhomatude)

    Hi — I’ve been trying all of the special mail tags and none of them seem to be working. Note that I am using contact form 8 variation. I just get back the mail tag ie: [_url] or [_post_title] or [_post_id]. I’ve tried putting the tags into the message body on the email notification – everywhere. And yes, the contact form is in a post.

    Takayuki Miyoshi

    (@takayukister)

    bhomatude, I don’t recommend the “contact form 8” as it’s just a bad copy of Contact Form 7. Of course you can’t use the special mail tags with the “contact form 8” because they are new features only Contact Form 7 supports. I suggest you to switch it to Contact Form 7 as soon as possible as Contact Form 7 has included many security fixes as well.

    bhomatude

    (@bhomatude)

    Update: problem is in the contact form 8. I uninstalled and went back to 7. Special mail tags work perfect in 7. Thanks Tak!

    Thread Starter Casemon

    (@casemon)

    Thank you Takayukister for the link & info! Will integrate this straight away!

    Thread Starter Casemon

    (@casemon)

    Actually, is there a way to get a page’s custom field info and put it as the TO: field?

    Have need for this.

    Takayuki Miyoshi

    (@takayukister)

    No. If you want to get custom field value you need to develop an add-on module yourself. Search ‘wpcf7_special_mail_tags’ in includes/classes.php.

    Thread Starter Casemon

    (@casemon)

    Ahh ok, will look into this.

    thanks for the info!

    Thread Starter Casemon

    (@casemon)

    Is there any more documentation on creating an add-on module?

    Maybe this will help.
    http://www.seodenver.com/contact-form-7-hidden-fields/
    It’s a module to use hidden fields.
    Maybe you could fill those hidden fields with the values of custom field.
    I am also very desperate for custom fields

    Thread Starter Casemon

    (@casemon)

    @1manfactory
    Thanks for this, it’s a good start.

    Am stuck on 1 thing:

    1) getting the page ID into my custom shortcode function; you cannot pass [_post_id] within a shortcode as far as I can tell, and $post->ID doesn’t work in the shortcode function (not sure why).

    Am happy to extend CF7, though really wish there was some documentation on all this, can’t seem to find API info on CF7.

    Thread Starter Casemon

    (@casemon)

    Ok, have managed to get this working partially. Ended up making a franken-add-on based on the various other modules.

    The good:
    Am seeing the value of the custom field if I include [customfield some-custom-field-name] in the form. Great.

    The bad / not working:
    If I add the customfield tag name to the Additional headers: area (the desired custom field happens to be an email) as in CC: [some-custom-field-name] <some-custom-field-email]>

    then the CC field is blank! The email has a blank entry for CC, as shown:
    Blank CC entry in resulting mail…

    Anyone know why this is?

    Here’s the module code if it helps:

    <?php
    /**
    ** contact form 7 module, which enables you to get the result of a custom field from the page that the form is on
    ** [customfield name] -> returns the value of a custom field on that post/page for [name]
    **/
    /* Shortcode handler */
    
    /* Shortcode handler */
    
    wpcf7_add_shortcode( 'customfield', 'wpcf7_customfield_shortcode_handler', true );
    function wpcf7_customfield_shortcode_handler($field) {
    	global $wpcf7_contact_form;
    	global $wp_query;
    	$thePostID = $wp_query->post->ID;
    	$somefield = get_post_meta($thePostID, $field[name], true);
    	if (empty($somefield)) return '';
    	return $somefield;
    }
    
    add_filter( 'wpcf7_validate_customfield', 'wpcf7_customfield_validation_filter', 10, 2 );
    function wpcf7_customfield_validation_filter( $result, $tag ) {
    	global $wpcf7_contact_form;
    
    	// $type = $tag['type'];
    	$name = $tag['name'];
    
    	$_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
    
    	return $result;
    }
    
    /* Tag generator */
    
    add_action( 'admin_init', 'wpcf7_add_tag_generator_customfield', 15 );
    function wpcf7_add_tag_generator_customfield() {
    	wpcf7_add_tag_generator( 'customfield', __( 'Custom Field', 'wpcf7' ),
    		'wpcf7-tg-pane-customfield', 'wpcf7_tg_pane_customfield' );
    
    }
    
    function wpcf7_tg_pane_customfield( $type = 'customfield' ) {
    	$type = 'customfield';
    
    ?>
    <div id="wpcf7-tg-pane-<?php echo $type; ?>" class="hidden">
    <form action="">
    <table>
    <tr><td><input type="checkbox" name="required" />&nbsp;<?php echo esc_html( __( 'Required field?', 'wpcf7' ) ); ?></td></tr>
    <tr><td><?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
    </table>
    
    <table>
    <tr>
    <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="id" class="idvalue oneline option" /></td>
    
    <td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="class" class="classvalue oneline option" /></td>
    </tr>
    
    <tr>
    <td><code>size</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="size" class="numeric oneline option" /></td>
    
    <td><code>maxlength</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <input type="text" name="maxlength" class="numeric oneline option" /></td>
    </tr>
    
    <tr>
    <td><?php echo esc_html( __( 'Akismet', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
    <?php if ( 'customfield' == $type ) : ?>
    <input type="checkbox" name="akismet:author" class="exclusive option" />&nbsp;<?php echo esc_html( __( "This field requires author's name", 'wpcf7' ) ); ?><br />
    <input type="checkbox" name="akismet:author_url" class="exclusive option" />&nbsp;<?php echo esc_html( __( "This field requires author's URL", 'wpcf7' ) ); ?>
    <?php endif; ?>
    </td>
    
    <td><?php echo esc_html( __( 'Default value', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /><input type="text" name="values" class="oneline" /></td>
    </tr>
    </table>
    
    <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="<?php echo $type; ?>" class="tag" readonly="readonly" onfocus="this.select()" /></div>
    
    <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code into the Mail fields below.", 'wpcf7' ) ); ?><br /><span class="arrow">⬇</span>&nbsp;<input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>
    </form>
    </div>
    <?php
    }
    
    ?>

    wpcf7_add_shortcode( 'customfield', 'wpcf7_customfield_shortcode_handler', true );
    function wpcf7_customfield_shortcode_handler($field) {
    	global $wpcf7_contact_form;
    	global $wp_query;
    	$thePostID = $wp_query->post->ID;
    	$somefield = get_post_meta($thePostID, $field[name], true);
    	if (empty($somefield)) return '';
    	return $somefield;
    }

    I think this can’t work. How do you try to post its value?

    Thread Starter Casemon

    (@casemon)

    Actually it does work, but only when the shortcode appears in the form; the shortcode doesn’t work in the mail fields…

    Any idea why?

    See shortcode handler functions in other modules, then you’ll find what they are supposed to do.

Viewing 15 replies - 1 through 15 (of 29 total)
  • The topic ‘[Plugin: Contact Form 7] Include originating page, or custom field from originating page?’ is closed to new replies.