Hube2 / contact-form-7-dynamic-select-extension

Dynamic Select Field for Contact Form 7
18 stars 8 forks source link

Return Label instead of value from validation filter #1

Open Hube2 opened 9 years ago

Hube2 commented 9 years ago

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

Hube2 commented 9 years ago

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 commented 8 years ago

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.

virgial commented 7 years ago

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);