Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using a custom post type name venue and I am using a <select> dropdown on one of the contact form by loading up a custom module in CF7 but when the form is submitted, my data shortcode is not replaced with the data filled by the user.

I just see this [selected-venue]. Here is my code for custom module:

<?php

wpcf7_add_shortcode( 'party-venue', 'wpcf7_venue_shortcode_handler', true );

function wpcf7_venue_shortcode_handler( $tag ) {

    global $wpdb;

    $query = "SELECT post_title FROM {$wpdb->posts} where post_type = 'venue' and post_status = 'publish';";

    $result = $wpdb->get_col( $query );

    if ( $result ) {
        $output = '<select name="contact_venue" id="contact_venue" class="input-select">';
        $output.= '<option></option>';
        foreach ( $result as $venue ) {
            $output.= '<option value="'.$venue.'">'.$venue.'</option>';
        }
        $output.= '</select>';
    }

    return $output;
}

My contact form's code is

<label for="contact_name"><span class="large_contact">name</span><span class="small_contact">Please enter your full name</span></label>[text* your-name class:input-textarea] 
<label for="contact_email"><span class="large_contact">email</span><span class="small_contact">Please enter a valid email address</span></label>[email* your-email class:input-textarea]
<label for="contact_phone"><span class="large_contact">phone</span><span class="small_contact">Please enter a phone number to reach you at</span></label>[text phone class:input-textarea]
<label for="contact_friends"><span class="large_contact">party size</span><span class="small_contact">*Min 50 guests for free bottle, 15 guests for buy 1 bottle get 1 free*</span></label>[text party-size class:input-textarea] </p>
<label for="contact_venue"><span class="large_contact">venue</span><span class="small_contact">Please select your party venue</span></label>[party-venue selected-venue id:contact_venue]
<label for="contact_date"><span class="large_contact">date</span><span class="small_contact">Please enter your party date (mm/dd/yy)</span></label>[text date id:contact_date class:input-textarea]
<label for="referal_source"><span class="large_contact">How did you hear about us?</span><span class="small_contact">Please select one of the options</span></label>[select menu-367 class:input-select "" "CitySearch" "Facebook" "Facebook Ad" "Friend" "Google Search" "NYC Daily Deals" "Yelp"]

[submit class:input-submit]

And here is my message body:

From: [your-name] <[your-email]>
Subject: Book a party!

Message Body:
Phone: [phone], 
Party Size: [party-size], 
Venue: [selected-venue], 
Date: [date]
How did you hear about us: [menu-367]

When I get the email on form submission, [selected-venue] is not replaced with the actual value of the select dropdown. What I am doing wrong?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Name of the input field should match with the filler shortcode so that it returns data. I changed $output = '<select name="contact_venue" to $output = '<select name="selected-venue" and it works now.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.