contact-form-7-dynamic-select-extension icon indicating copy to clipboard operation
contact-form-7-dynamic-select-extension copied to clipboard

Return Label instead of value from validation filter

Open Hube2 opened this issue 9 years ago • 3 comments

From this topic on support forum https://wordpress.org/support/topic/label-instead-of-value-in-mail?replies=3

Hube2 avatar Jul 31 '15 11:07 Hube2

I have looked into doing this and am having difficulty figuring out how. Mostly do to the poor documentation of CF7.

If anyone would like to take a look at this and suggest how it can be done or add it to the code and do a pull request....

Hube2 avatar Oct 11 '15 13:10 Hube2

Please see my comment here about the difficulties with adding this feature https://wordpress.org/support/topic/label-instead-of-value-in-mail?replies=3#post-7930669

Like I said here and there, if anyone can work out how this is done in CF7. The filters and hooks available in CF7 are not well documented.

Hube2 avatar Mar 26 '16 17:03 Hube2

Hi Hube2, I think you're looking for the filter wpcf7_posted_data. I've used it for changing post ID's to readable post titles in the sending e-mail. Hope it helps.

function modify_wpcf7_posted_data($items)
{
    $tag = 'myselecttag';
    // do nothing if we have nothing
    if (!isset($items[$tag])) return $items;
    
    // $items['tag'] is array of ID's or single ID
    if (!is_array($items[$tag])) $items[$tag] = array($items[$tag]);
  
    $ps = get_posts(array('post__in'=>$items[$tag]));
    $items[$tag] = '';
    foreach($ps as $p) $items[$tag] .= $p->post_title."\r\n";
    return $items;
}
add_filter('wpcf7_posted_data', 'modify_wpcf7_posted_data',10,2);

virgial avatar Nov 29 '16 13:11 virgial