Home › Forum › Plugin e temi di WP › Contact Form 7 – option value visualizzato in un div/text field
-
AutorePost
-
-
10 Luglio 2017 alle 7:58 #31482msuPartecipante
Buongiorno a tutti!
Ho una domanda su Contact Form 7 che non ha trovato risposta in nessun forum online.
Ho un menu a discesa come questo:
[select* prefix-city “City|—†“Milan|02†“Rome|06†“Bologna|051â€]
Vorrei fare sଠche, una volta selezionata la propria città , l’option value (il valore a destra della “|”) compaia in un div all’interno del form (oppure in un text field).
Quindi se seleziono “Milano”, in un altro campo del form comparirà il prefisso di Milano “02”.
Esiste una soluzione semplice?
-
10 Luglio 2017 alle 16:34 #121744TittiModeratore
La soluzione più semplice è creare un altro campo manuale (cioè selezionabile dall’utente) con il prefisso, che preceda il campo della città . Oppure anteponi i rispettivi prefissi direttamente nei campi opzionali delle città , perché CF7 di default non crea campi aggiuntivi automatici o dinamici, quindi dovrai farlo attraverso una funzione o un plugin.
Come usi tu il pipe ( “|”) non serve a niente, perché in CF7 il valore a sinistra del pipe è visibile dall’utente, quello a destra è nascosto. Utile in un menu a discesa con le varie opzioni a chi inviare la email: “qualifica o nome del ricevente | rispettiva e-mail”: l’utente sceglierà a chi mandare la richiesta in base alla qualifica o nome visibile, ma non vedrà l’email del ricevente, che apparirà solo nel campo To: dell’email.
Per aggiungere campi dinamici in base a scelte opzionali o crei tu una funzione se sei in grado, oppure guarda se c’è il plugin che fa al caso tuo tra questi:
https://it.wordpress.org/plugins/contact-form-7-city-field-extension/
https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/
https://wordpress.org/plugins/contact-form-7-dynamic-select-extension/
-
11 Luglio 2017 alle 8:06 #121745msuPartecipante
Grazie mille! Mi sa che l’unica è creare un’opzione ad hoc.
Ci sono quasi riuscito, incappo però in un problema banale: contact form 7 non “legge” l’option value.
Ovvero, questo tag:
[select* prefix-city id:prefisso class:inputsx first_as_label “City|—†“Milan|02†“Rome|06†“Bologna|051â€]
Genera questo codice nella pagina (lavoro in locale, altrimenti metterei il link):
<select name=”prefix-city” class=”wpcf7-form-control wpcf7-select wpcf7-validates-as-required inputsx” id=”prefisso” aria-required=”true” aria-invalid=”false”><option value=””>City</option><option value=”Milan”>Milan</option><option value=”Rome”>Rome</option><option value=”Bologna”>Bologna</option></select>
Ho cercato ma non ho trovato risposte, se non questa: https://wordpress.org/support/topic/cf7-pipes-not-working/ che però non chiarisce nulla. O l’option value funziona solo con le email? (ho provato a mettere una mail dopo il pipe, ma non cambia nulla).
Se uso gli “strumenti per sviluppatori” di Chrome e intervengo sulla pagina modificando la stringa cosà¬: <option value=”02″>Milan</option> tutto funziona. Peccato che CF7 non legga il valore dopo il pipe.
ps: il “WPCF7_USE_PIPE” è settato naturalmente su “true”.
-
11 Luglio 2017 alle 10:54 #121746TittiModeratore
Il sistema dei pipe funziona, e non c’è bisogno di definirlo true dato che lo è di default – quindi in questo caso il define serve solo se è false.
Come dice qui funziona nelle selezioni, quindi drop-down menu come nel tuo caso o radio button – tra l’altro questo link era già consigliato in risposta nella pagina che hai linkato tu sopra, ma evidentemente non l’hai aperto.
Se l’avessi letto avresti visto che se vuoi fare un select, ad esempio, persona|indirizzo, non basta mettere “una mail” dopo il pipe: è chiaro che se nel modulo dopo “select” hai scritto, ad es., your-recipient, o email-recipient, poi nel form Mail in A dovrai scrivere la stessa cosa [your-recipient] o [email-recipient] (troverai scritti in alto i mail-tag da utilizzare in base a quelli che hai messo nel modulo), altrimenti va da sé che se lଠhai un indirizzo statico la mail arriva a quell’indirizzo specificato.
La stessa cosa vale per qualsiasi mail-tag tu scelga: se usi “prefix-city” poi dovrai inserire quello stesso mail-tag nel form “Mail” nel punto in cui vuoi che appaia in chiaro il valore dopo il pipe quando arriva l’email; se non ce lo metti è inutile far selezionare all’utente una cosa che poi non puoi leggere (o far funzionare, nel caso dell’indirizzo) nella mail di destinazione.
Il valore dopo il pipe sarà sempre invisibile all’utente che compila il form: se si usa per la maggior parte con indirizzi email è perché ha senso che l’utente non legga gli indirizzi, quindi personalmente non mi è chiaro a cosa ti serva nascondere e poi leggere il prefisso (o leggerlo al posto della città ) nella mail, in definitiva se ha senso renderlo nascosto, ma quelli sono affari tuoi . L’importante è che tu capisca che il concetto e l’utilizzo sono quelli indipendentemente da cosa scegli di nascondere e leggere nella mail del ricevente.
Spero sia chiaro.
PS: se fai varie prove devi sempre svuotare la cache
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.