Controllo lunghezza minima form su wordpress
-
Anche con cforms non trovo la funzione.
L'ho detto cosa devo fare: un visitatore mi deve mandare i suoi dati ed una descrizione della sua attività che deve avere un minimo di lunghezza.
-
-
Anche questo ultimo plugin ha solo la funzione maxlength.
Trovo assurdo tutto questo.
Eppure trovo milioni di form che hanno la funzionalità lunghezza minima.
Provo a rintracciare uno di questi forum e vedere che software hanno usato.
(Anche diggita.it per esempio ha questa funzione). -
-
-
valijolie
marta, altrimenti tagliamo la testa al toro: guardiamo il codice del tuo form ed aggiungiamo il controllo che ti manca

Veramente grazie a tutti per la disponibilità e gentilezza.

-
Se per favore date una occhiata a questo plugin:
wordpress.org/extend/plugins/mm-forms-community/
Per inserire quel controllo sulla lunghezza del testo minimo.
Oltre al fatto che ve ne sarei molto grata, è sicuramente un qualcosa utile anche per altri.

-
Dopo aver notato che nel 100% dei plugin da me testati manca il minlength per il testo di un campo (manca anche nei form html) vi invio qui la parte di validazione (sperando sia questa quella che serve) del file mmforms.php del plugin mmforms community.
In modo che inserite quel controllo per la textarea o un altro campo, vedete voi.
Grazie, ciaofunction validate($contact_form) { $fes = $this->form_elements($contact_form['form'], false); $valid = true; $reason = array(); foreach ($fes as $fe) { $type = $fe['type']; $name = $fe['name']; $values = $fe['values']; // Before validation corrections if (preg_match('/^(?:text|email) [*]?$/', $type)) $_POST[$name] = trim(strtr($_POST[$name], "\n", " ")); if (preg_match('/^(?:select|checkbox|radio) [*]?$/', $type)) { if (is_array($_POST[$name])) { foreach ($_POST[$name] as $key => $value) { if (! in_array($value, $values)) // Not in given choices. unset($_POST[$name][$key]); } } else { if (! in_array($_POST[$name], $values)) // Not in given choices. $_POST[$name] = ''; } } if ('acceptance' == $type) $_POST[$name] = $_POST[$name] ? 1 : 0; // Required item (*) if (preg_match('/^(?:text|textarea|checkbox) [*]$/', $type)) { if (empty($_POST[$name])) { $valid = false; $reason[$name] = $this->message('invalid_required'); } } if ('select*' == $type) { if (empty($_POST[$name]) || ! is_array($_POST[$name]) && '---' == $_POST[$name] || is_array($_POST[$name]) && 1 == count($_POST[$name]) && '---' == $_POST[$name][0]) { $valid = false; $reason[$name] = $this->message('invalid_required'); } } if (preg_match('/^email [*]?$/', $type)) { if ('*' == substr($type, -1) && empty($_POST[$name])) { $valid = false; $reason[$name] = $this->message('invalid_required'); } elseif (! empty($_POST[$name]) && ! is_email($_POST[$name])) { $valid = false; $reason[$name] = $this->message('invalid_email'); } } if (preg_match('/^captchar$/', $type)) { $captchac = '_mmf_captcha_challenge_' . $name; if (! $this->check_captcha($_POST[$captchac], $_POST[$name])) { $valid = false; $reason[$name] = $this->message('captcha_not_match'); } $this->remove_captcha($_POST[$captchac]); } } return compact('valid', 'reason'); } -
Ciao marta_de_angelis,
puoi provare ad utilizzare il codice qui sotto:function validate($contact_form) { $fes = $this->form_elements($contact_form['form'], false); $valid = true; $reason = array(); foreach ($fes as $fe) { $type = $fe['type']; $name = $fe['name']; $values = $fe['values']; // Before validation corrections if (preg_match('/^(?:text|email) [*]?$/', $type)) $_POST[$name] = trim(strtr($_POST[$name], "\n", " ")); if (preg_match('/^(?:select|checkbox|radio) [*]?$/', $type)) { if (is_array($_POST[$name])) { foreach ($_POST[$name] as $key => $value) { if (! in_array($value, $values)) // Not in given choices. unset($_POST[$name][$key]); } } else { if (! in_array($_POST[$name], $values)) // Not in given choices. $_POST[$name] = ''; } } if ('acceptance' == $type) $_POST[$name] = $_POST[$name] ? 1 : 0; // Required item (*) if (preg_match('/^(?:text|textarea|checkbox) [*]$/', $type)) { if (empty($_POST[$name])) { $valid = false; $reason[$name] = $this->message('invalid_required'); } else{ if ($_POST[$name]=="nome_Campo_da_Validare") { $lunghezza_minima=500; //500caratteri inclusi spazi e punteggiatura if(strlen($_POST[$name])<$lunghezza_minima) { $valid = false; $reason[$name] = "Il testo inserito è troppo corto"; } } } if ('select*' == $type) { if (empty($_POST[$name]) || ! is_array($_POST[$name]) && '---' == $_POST[$name] || is_array($_POST[$name]) && 1 == count($_POST[$name]) && '---' == $_POST[$name][0]) { $valid = false; $reason[$name] = $this->message('invalid_required'); } } if (preg_match('/^email [*]?$/', $type)) { if ('*' == substr($type, -1) && empty($_POST[$name])) { $valid = false; $reason[$name] = $this->message('invalid_required'); } elseif (! empty($_POST[$name]) && ! is_email($_POST[$name])) { $valid = false; $reason[$name] = $this->message('invalid_email'); } } if (preg_match('/^captchar$/', $type)) { $captchac = '_mmf_captcha_challenge_' . $name; if (! $this->check_captcha($_POST[$captchac], $_POST[$name])) { $valid = false; $reason[$name] = $this->message('captcha_not_match'); } $this->remove_captcha($_POST[$captchac]); } } return compact('valid', 'reason'); } }Non ho testato il codice ma mi sembra possa funzionare. Puoi personalizzare
$lunghezza_minimaa seconda della lunghezza necessaria.
Questa riga inveceif ($_POST[$name]=="nome_Campo_da_Validare")va modificata sostituendo nome_Campo_da_Validare con il valore "name" dell'input type='text' o della textarea
contenente la descrizione.
Naturalmente questa modifica andrà replicata ogni volta che aggiornerai il plugin.
Fammi sapere se funziona tutto.
-
Per ora sto ricevendo
Parse error: syntax error, unexpected T_VAR
qui mi sembra:
var $__form_id = 0;
function set_formid($form_id){$this->__form_id = $form_id; }Come mai?
Grazie

-
Mi è sfuggita una parentesi graffa nel copia/incolla
il codice è quindi:function validate2($contact_form) { $fes = $this->form_elements($contact_form['form'], false); $valid = true; $reason = array(); foreach ($fes as $fe) { $type = $fe['type']; $name = $fe['name']; $values = $fe['values']; // Before validation corrections if (preg_match('/^(?:text|email) [*]?$/', $type)) $_POST[$name] = trim(strtr($_POST[$name], "\n", " ")); if (preg_match('/^(?:select|checkbox|radio) [*]?$/', $type)) { if (is_array($_POST[$name])) { foreach ($_POST[$name] as $key => $value) { if (! in_array($value, $values)) // Not in given choices. unset($_POST[$name][$key]); } } else { if (! in_array($_POST[$name], $values)) // Not in given choices. $_POST[$name] = ''; } } if ('acceptance' == $type) $_POST[$name] = $_POST[$name] ? 1 : 0; // Required item (*) if (preg_match('/^(?:text|textarea|checkbox) [*]$/', $type)) { if (empty($_POST[$name])) { $valid = false; $reason[$name] = $this->message('invalid_required'); } else{ if ($_POST[$name]=="nome_Campo_da_Validare") { $lunghezza_minima=500; //500caratteri inclusi spazi e punteggiatura if(strlen($_POST[$name])<$lunghezza_minima) { $valid = false; $reason[$name] = "Il testo inserito è troppo corto"; } } } if ('select*' == $type) { if (empty($_POST[$name]) || ! is_array($_POST[$name]) && '---' == $_POST[$name] || is_array($_POST[$name]) && 1 == count($_POST[$name]) && '---' == $_POST[$name][0]) { $valid = false; $reason[$name] = $this->message('invalid_required'); } } if (preg_match('/^email [*]?$/', $type)) { if ('*' == substr($type, -1) && empty($_POST[$name])) { $valid = false; $reason[$name] = $this->message('invalid_required'); } elseif (! empty($_POST[$name]) && ! is_email($_POST[$name])) { $valid = false; $reason[$name] = $this->message('invalid_email'); } } if (preg_match('/^captchar$/', $type)) { $captchac = '_mmf_captcha_challenge_' . $name; if (! $this->check_captcha($_POST[$captchac], $_POST[$name])) { $valid = false; $reason[$name] = $this->message('captcha_not_match'); } $this->remove_captcha($_POST[$captchac]); } } return compact('valid', 'reason'); } }ho corretto anche il post precedente

-
Ho impostato così
if ($_POST[$name]=="your-message")Per questo form
<form action="/prova/#outcome_msg" method="post" class="mmf-form" enctype="multipart/form-data"> <input type="hidden" name="_mmf" value="1" /><input type="hidden" name="_mmf_success_url" value="" /> <input type="hidden" name="_mmf_failure_url" value="" /><input type="hidden" name="_mmf_unit_tag" value="mmf-f1-p459-o1" /> <input type="hidden" name="page_post_id" value="459" /> <input type="hidden" name="page_post_title" value="prova" /> <p><label>Your Name (required)<br /> <span class="mmf-form-control-wrap your-name"> <input type="text" name="your-name" value="" class="mmf-validates-as-required" size="40" /></span> </label></p> <p><label>Your Email (required)<br /> <span class="mmf-form-control-wrap your-email"> <input type="text" name="your-email" value="" class="mmf-validates-as-email mmf-validates-as-required" size="40" /></span> </label></p> <p><label>Subject<br /> <span class="mmf-form-control-wrap your-subject"> <input type="text" name="your-subject" value="" size="40" /></span> </label></p> <p><label>Your Message<br /> <span class="mmf-form-control-wrap your-message"><textarea name="your-message" cols="40" rows="10"></textarea></span> </label></p> <p><input type="submit" value="Send" /> <img class="ajax-loader" style="visibility: hidden;" alt="ajax loader" src="nomedominio/wp-content/plugins/mm-forms-community/images/ajax-loader.gif" /></p> </form>Ma purtroppo non funziona. Non da errore ma non funziona e non arriva l'email dei dati del form.
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi