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" /> <?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" /> <?php echo esc_html( __( "This field requires author's name", 'wpcf7' ) ); ?><br />
<input type="checkbox" name="akismet:author_url" class="exclusive option" /> <?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> <input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>
</form>
</div>
<?php
}
?>