Forums

[resolved] [Plugin: Contact Form 7] How to pull mail recipient from Post's cusom field? (10 posts)

  1. Valdi
    Member
    Posted 2 years ago #

    Hi,

    Each of my posts have their unique email's as Custom Field and a contact form.

    How can I pull the mail recipient of Contact Form 7 from the post's email custom field?

    So the email is sent to the post's email.

    Thanks in advance. :)

  2. Valdi
    Member
    Posted 2 years ago #

    Any help?

  3. Takayuki Miyoshi
    Member
    Posted 2 years ago #

    Contact Form 7 doesn't pull data from custom fields. It will require some code customization.

  4. Valdi
    Member
    Posted 2 years ago #

    What about hidden fields?

  5. Takayuki Miyoshi
    Member
    Posted 2 years ago #

    How do you use hidden fields?

  6. Valdi
    Member
    Posted 2 years ago #

    Copy the form's code on preview and add it manually and then add a Hidden Field.

    <input type="hidden" id="receiver" name="receiver" value="email@company.com"/>

  7. Valdi
    Member
    Posted 2 years ago #

    I've managed to fix this problem by adding my own form.

  8. g01010
    Member
    Posted 2 years ago #

    Hi Valdi

    Could you share any more information on how you solved this? I've been looking for an answer to this for some time now.

    Thanks.

  9. BAC
    Member
    Posted 1 year ago #

    I put up a post about achieving this - (all credit to Phycel (http://wordpress.org/support/profile/phycel) for the hack)

    http://anniebay.com/contact-form-7-recipient-email-from-custom-field/

  10. jroakes
    Member
    Posted 1 year ago #

    Here is a very easy way of doing this:

    Just follow the instructions at the top of the script.

    <?php
    /**
    ** A base module for [hidden customfield]
    **
    **--Instructions--
    ** Put this script as a file (hidden_custom.php) into the plugins/contact-form-7/modules/ folder.
    ** "Hidden Custom Field" should now be an option in the "Generate Tag" dropdown of your contact form.
    ** Type the name of your custom field in the "The Custom Field name goes here" field.
    ** Put the 2 generated into the form and email as indicated.
    **
    **/
    
    // Shortcode handler
    
    wpcf7_add_shortcode( hidden, 'wpcf7_hidden_shortcode_handler', true );
    
    function wpcf7_hidden_shortcode_handler( $tag ) {
    	if ( ! is_array( $tag ) )
    		return '';
    
    	$name = $tag['name'];
    
    	$options = (array) $tag['options'];
    	$values = (array) $tag['values'];
    
    	$atts = '';
    	$id_att = '';
    
    	$class_att .= ' wpcf7-hidden';
    
    	foreach ( $options as $option ) {
    		if ( preg_match( '%^id:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
    			$id_att = $matches[1];
    		}
    	}
    
    	if ( $id_att )
    		$atts .= ' id="' . trim( $id_att ) . '"';
    
    	global $wp_query;
    
    	$postid = $wp_query->post->ID;
    
    	$theCustomValue = get_post_meta($postid, $name , true);
    
    	$value = $theCustomValue;
    
    	$html = '<input name="'.$name.'" type="hidden" value="' . esc_attr( $value ) . '"' . $atts . ' />';
    
    	return $html;
    }
    
    // Tag generator
    
    add_action( 'admin_init', 'wpcf7_add_tag_generator_hidden', 50 );
    
    function wpcf7_add_tag_generator_hidden() {
    	wpcf7_add_tag_generator( 'hidden', __( 'Hidden Custom Field', 'wpcf7' ),
    		'wpcf7-tg-pane-hidden', 'wpcf7_tg_pane_hidden' );
    }
    
    function wpcf7_tg_pane_hidden( &$contact_form ) {
    ?>
    <div id="wpcf7-tg-pane-hidden" class="hidden">
    <form action="">
    <table>
    <tr><td><?php echo esc_html( __( 'The Custom Field name goes here', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
    </table>
    <!-- I am killing these because they are not needed.  I am leaving them in case someone wants to modify this code.
    <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>
    
    </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="hidden" class="tag" readonly="readonly" onfocus="this.select()" /></div>
    
    <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code anywhere in the emails below.", 'wpcf7' ) ); ?><br /><span class="arrow" style="font-size:20px;">&rarr;</span>&nbsp;<input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>
    </form>
    </div>
    <?php
    }
    
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic