Viewing 13 replies - 1 through 13 (of 13 total)
  • I’m interested to this question too.
    I’d like to insert a dropdown with a city list…

    Regards, Nicola

    Thread Starter jaccia

    (@jaccia)

    Nicola,

    It’s always good to know I’m not alone.
    Jacci

    Probabily the answer is “shortcode”…
    Hope that Michael could save us πŸ˜€

    Plugin Author Michael Simpson

    (@msimpson)

    I don’t know of a way to do it if you are using CF7. This is because you use the CF7 short code to generate the form HTML but we would need to change how the form HTML is generated.

    Alternatively, if you were to create your own form by writing your own HTML (not using CF7), then you could do it. In that case you would also have to add a short code for CFDB to capture the data (see http://cfdbplugin.com/?page_id=508).

    In such a case, you create the form HTML and use a short code to fill out the choices in part of the form. For example, you have a form like this:

    [cfdb-save-form-post]
    <form action="" method="post">
       <input type="hidden" name="form_title" value="Registration"/>
       First Name: <input type="text" name="fname" value=""/><br/>
       Last Name: <input type="text" name="lname" value=""/><br/>
    <select name="Team">
        <option value="Team1">Team1</option>
        <option value="Team2">Team2</option>
        <option value="Team3">Team3</option>
    </select><br/>
       <input type="submit" />
    </form>

    But you want the Team option values to be populated by a short code that pulls team names from CFBD that were submitted previously in a “Teams” form that had “team_name” fields, then you could replace the option tags with a short code like:

    [cfdb-save-form-post]
    <form action="" method="post">
       <input type="hidden" name="form_title" value="Registration"/>
       First Name: <input type="text" name="fname" value=""/><br/>
       Last Name: <input type="text" name="lname" value=""/><br/>
    <select name="Team">
        [cfdb-html form="Teams" show="team_name"]
        <option value="${team_name}">${team_name}</option>
        [/cfdb-html]
    </select><br/>
       <input type="submit" />
    </form>

    There is a more complex case involving a “cascading” where you might have a “state” list and based on the user’s selection of that, “city” field choices automatically update to be consistent with the state choice. That case would require writing some Javascript and making AJAX calls that effectively do what the short code does, it just does it on the fly.

    Thread Starter jaccia

    (@jaccia)

    Michael – Thank you for responding.

    I’ve done what you suggested here’s my code:

    [cfdb-save-girls-summerchill]
    <form action="" method="post" enctype="multipart/form-data">
       <input type="hidden" name="form_title" value="Player Girls Summer Chill"/>
    <p>Team <select name="TeamName">
        [cfdb-html form="Coach Girls Summer Chill" show="TeamName"]
        <option value="${TeamName}">${TeamName}</option>
        [/cfdb-html]
    </select></p>
    <p>
    School <input type="text" name="PlayerSchool" value=""/><br/>
    
    Position <select name="PlayerPosition">
    <option value="PlayerPosition1">Attack</option>
    <option value="PlayerPosition2">Attack/Midfield</option>
    <option value="PlayerPosition3">Defense</option>
    <option value="PlayerPosition4">Long Stick Midfield</option>
    <option value="PlayerPosition5">Goalie</option>
    </select><br/>
    
    Player Date of Birth <input type="text" name="PlayerDOB" value=""/><br/></p>
    
    <input type="submit" />
    </form>

    Here’s the error message:

    [cfdb-save-girls-summerchill]="<br />
    <b>Parse error</b>:  syntax error, unexpected '<' in <b>/home/content/84/8783984/html/wp-content/plugins/shortcode-exec-php/shortcode-exec-php-class.php(1069) : eval()'d code</b> on line <b>1</b><br /

    I’m not a PHP expert so I have no idea what the error message means.

    Thanks for your help on this. I appreciate it.

    Plugin Author Michael Simpson

    (@msimpson)

    Looks like you created a custom short code [cfdb-save-girls-summerchill] and it has a syntax error in it. The form tag you show here looks OK.

    Hi guys…
    I know that the original question is a bit different from mine: i need to populate a dropdown list from my own db’s table.

    In this way I can use all ContactForm7 goodies:
    In the cf

    [text* nome /40]
    [email* email /90]
    <select name="provincia">[lista_province]</select>

    In a code file

    wpcf7_add_shortcode( 'lista_province', 'lista_province_da_db');
    function lista_province_da_db ( $atts ) {
    	global $wpdb;
    	$sql = "SELECT p.id_provincia AS valore, p.provincia AS label
    			FROM tab_province AS p
    			ORDER BY p.provincia;";
    	$ret = "";
    	$righe = $wpdb->get_results($sql);
    	foreach ( $righe as $riga ) {
    		$ret .= '<option value="' . $riga->valore . '">' . $riga->label . '</option>';
    	}
    
    	return $ret;
    }

    Hope this post can help someone!

    Plugin Author Michael Simpson

    (@msimpson)

    Ideally, it would be nice if you could nest a short code inside of a CF7 form definition like:
    [select menu-629 "[my-list]"]
    Where [my-list] would be a custom short code you would define using the ‘Shortcode Exec PHP’ plugin that would query the DB for a list of items to select that you want…

    ….but I tried it and it does NOT work.

    But… If the nested shortcode would query the DB for the list of items… The outer shortcode what would do?!…

    Plugin Author Michael Simpson

    (@msimpson)

    That outter short code is not exactly a short code. When you go to the CF7 editor to create a CF7 short code, that is an example of a select field inside the CF7 form definition.

    Thread Starter jaccia

    (@jaccia)

    To shark986:

    You wrote “In a code file”. What code file do I put the block of code you created in?

    I’m hoping what you did will work for me.

    Thanks,
    Jacci

    Jaccia..
    I’m writing a plugin, so that code is part of it.

    I think you should put that code in the functions.php file too.
    Remember that upgrading or changing the template you will lost that funcionality!

    Is there any option to bring the data’s of any other databases to the drop down box in the contact form 7

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Plugin: Contact Form 7 to Database Extension] How to get data into a CF7 dropdown’ is closed to new replies.