Problem with Select PLEASE HELP!!
-
Hello
i created a form with CF7, in this form i have two selects.
These selects are populated with two functions in functions.php.The values of these two selects are not saved with CFDB, values are empty.
I have another select in this form, also this select is populated with a function, but all works fine.
I can’t understand why and how to fix it.
HELP ME PLEASE!!
https://ww.wp.xz.cn/plugins/contact-form-7-to-database-extension/
-
Please provide a detailed example of how you populated the selects in a form.
Ok, i create a shortcode, this is the function:
wpcf7_add_shortcode(‘corsidropdown’, ‘createbox’, true);
function createbox(){
global $post;
extract( shortcode_atts( array( ‘post_type’ => ‘some_post_type’,), $atts ) );
$post_id = $_GET[“corso”];
$posts = get_posts(array(
‘post_type’ => ‘corsi-custom’,
‘posts_per_page’ => -1,
‘orderby’ => ‘title’,
‘order’ => ‘ASC’
));
if($posts)
{
$output = “<select id=’corsi’>”;
$link_corso_default = ‘http://www.esi-italy.it/iscrizione/?corso=’.$post_id;
$title_corso_default = get_the_title($post_id);
$output .= “<option value=’$link_corso_default’>$title_corso_default</option>”;
foreach($posts as $post) {
$link_corso = ‘http://www.esi-italy.it/iscrizione/?corso=’.$post->ID;
$title_corso = get_the_title($post->ID);
$output .= “<option value=’$title_corso’>$title_corso</option>”;
}
$output .= “</select>”;
return $output;
}}
In the form i use this shortcode in this way: [corsidropdown corsi]
Would you post your CF7 form definition also?
And use the “code” button to format it in the post
This is the form:`
<div class=”form-iscrizione-corsi”>
<h1>Modulo di iscrizione</h1>
<div class=”selezione-corso-sessione”>
<h2>Dettagli corso</h2>
[corsidropdown corsi]
[sessionidropdown sessioni]
</div><div class=”form-iscrizione-data”>
<h2>Dettagli partecipante</h2>
<div class=”form-iscrizione-data-left”>
[text* nome placeholder “Nome*”]
[text* funzione placeholder “Funzione*”]
[text* indirizzo placeholder “Indirizzo*”]
[text* citta placeholder “Città*”]
[text* provincia placeholder “Provincia*”]
[text* stato placeholder “Stato*”]
[email* email placeholder “Indirizzo email*”]
</div><div class=”form-iscrizione-data-right”>
[text* cognome placeholder “Cognome*”]
[text* azienda placeholder “Azienda*”]
[text* piva_codfisc placeholder “Cod.Fiscale/P.Iva*”]
[text* cap placeholder “CAP*”]
[text* telefono placeholder “Telefono*”]
</div>
</div>
<div class=”form-iscrizione-data-full-width”>
<h2>Dove hai trovato la notizia di questo corso?</h2>
[domandedropdown domande]
[text* quale placeholder “Quale?”]
</div><div class=”form-iscrizione-data-full-width”>
<div class=”form-iscrizione-consenso”>
<h2>Consenso alla partecipazione dato da:</h2>
[text nome_consenso placeholder "Nome"]
[text cognome_consenso placeholder "Cognome"]
[text funzione_consenso placeholder "Funzione"]
[text telefono_consenso placeholder "Telefono"]
[text email_consenso placeholder "Email"]
</div>
</div><div class=”form-iscrizione-fatturazione”>
<h2>Dettagli per fatturazione se diversi da quanto scritto sopra:</h2>
[text ragione_sociale_fatt placeholder "Ragione Sociale/Nome e Cognome"]
[text indirizzo_fatt placeholder "Indirizzo Aziendale/Privato"]
[text telefono_fatt placeholder "Telefono Aziendale/Privato"]
[text email_fatt placeholder "Email aziendale/Privata"]
[text piva_fatt placeholder "Partita IVA/Codice Fiscale"]
</div><div class=”form-iscrizione-pagamento”>
<h2>Modalità di pagamento</h2>
[radio modalita_pagamento default:1 “Fotocopia del bollettino di versamento effettuato sul c/c postale nr. 16834202” “Assegno bancario – assegno circolare” “Bonifico bancario (Banca Popolare di Sondrio – Ag. 10 Milano, via Solari, 15). c/c 000002805X07 – ABI 05696 – CAB 01609 – CIN Z – Swift POSOIT22 – IBAN IT29 Z056 9601 6090 0000 2805 X07”]
</div><div class=”form-consenso”>
<h2>Consenso al trattamento di dati personali (*)</h2>
<p>
Dichiaro di avere letto l’informativa, e tramite il conferimento dei miei dati acconsento al trattamento per le finalità indicate.
Acconsento al trattamento dei miei dati personali per finalità promozionali effettuate da parte dell’Istituto Internazionale di Ricerca s.r.l. Unipersonale, anche tramite la definizione di proposte commerciali o alla comunicazione di informazioni maggiormente attinenti ai miei interessi
</p>
<p> [checkbox* ACCONSENTO1 “ACCONSENTO”] </p>
<p>Acconsento alla comunicazione dei miei dati personali a soggetti terzi per comunicazioni in merito a loro iniziative.</p>
<p> [checkbox* ACCONSENTO2 “ACCONSENTO”] </p>
</div><p>[submit “Iscriviti”]</p>
</div>There is a lot of stuff going on there. I made my own example to test. I can reproduce the issue. It appears to me that CF7 is not recognizing the SELECT’s NAME attribute.
Ignoring CFDB for a moment, if I set the custom tag in the CF7 email template, I can see that it does not get populated in the email, implying that CF7 is not processing it. As a general rule, if you can’t get it to show in the CF7 email, then CFDB cannot see it also. Therefore it is an issue inside CF7.
The workaround I found was to set the NAME in the code that generates the select instead of in the CF7 custom shortcode.
Specifically for you change:
$output = "<select id='corsi'>";
to
$output = "<select id='corsi' name='corsi'>";This means that
[corsidropdown corsi]should just be[corsidropdown]and
wpcf7_add_shortcode('corsidropdown', 'createbox', true);
should just be:
wpcf7_add_shortcode('corsidropdown', 'createbox');Here is a more simple test case. You should pass this on to the CF7 forum:
This does NOT work:
CF7 Form definition:<p> Your Car [carselect car] </p> <!-- name "car" provided --> <p>[submit "Send"]</p>Registering custom short code:
add_action('wpcf7_init', 'add_cf7_carselect_shortcode'); function add_cf7_carselect_shortcode() { wpcf7_add_shortcode('carselect', 'cf7_car_select', true); } function cf7_car_select() { // NOT setting "name" below return '<select id="car"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select>'; }But this DOES work
CF7 Form definition:<p> Your Car [carselect] </p> <!-- no name --> <p>[submit "Send"]</p>Registering custom short code:
add_action('wpcf7_init', 'add_cf7_carselect_shortcode'); function add_cf7_carselect_shortcode() { //wpcf7_add_shortcode('carselect', 'cf7_car_select', true); wpcf7_add_shortcode('carselect', 'cf7_car_select'); } function cf7_car_select() { // Explicitly setting "name" below return '<select name="car" id="car"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select>'; }GREAT!! GREAT!!
And another time, GREAT!
It works perfectly!
You just saved me, thank you so much!!Now that you got me to learn CF7 custom form tags, I was inspired to document how to create a CF7 custom tag with select options coming from CFDB form submissions.
Great!
This goes straight to my collection “essential links”
The topic ‘Problem with Select PLEASE HELP!!’ is closed to new replies.