Accueil > Divers > Infographiste > CMS > Typo3 > Créer des formulaires avec Mailformplus

Créer des formulaires avec Mailformplus

sous Typo3

dimanche 7 décembre 2008, par Philippe Donnart

Voici une extension qui permet de créer des formulaires sous Typo3, avec un contrôle des champs et redirection après validation.

Voici le code du template utilisé pour le formulaire en capture d’écran
à quelque chose près, les champs obligatoires * ont été modifiés.

<!-- ###TEMPLATE_FORM### begin -->
###ERROR###
<form name="Formular" method="post" action="###REL_URL###" enctype="multipart/form-data">
	<fieldset>
		<legend>Devis gratuit</legend>
<input type="hidden" name="id" value="###PID###" />
<input type="hidden" name="submitted" value="1" />
<input type="hidden" name="L" value="###value_L###" />
<input type="hidden" name="type" value="###value_type###" />


	<label for="topic" accesskey="t">Vous êtes</label>
	<select name="topic" style="width:100px;" tabindex="1">
		<option value="leer" ###selected_topic_leer###></option>
		<option value="particulier" ###selected_topic_particulier###>Particulier</option>
		<option value="entreprise" ###selected_topic_entreprise###>Entreprise</option>
		</select>
	<br/>
	<label for="name" accesskey="n">Nom et prénom *</label>
	<input type="text" name="name" id="name" value="###value_name###" tabindex="2"/>
	<br/>
	<label for="societe" accesskey="s">Titre ou Société</label>
	<input type="text" name="societe" id="societe" value="###value_societe###" tabindex="3"/>
	<br/>
	<label for="phone" accesskey="p">Téléphone *</label>
	<input type="text" name="phone" id="phone" value="###value_phone###" tabindex="4"/>
	<br/>
	<label for="email" accesskey="e">e-mail *</label>
	<input type="text" name="email" id="email" value="###value_email###" tabindex="5"/>
	<br/>
	<label for="date" accesskey="s">Date (exemple 24/12/2008)</label>
	<input type="text" name="date" id="date" value="###value_date###" tabindex="6"/>
	<br/>
	<label for="adulte" accesskey="a">nombre d'adultes</label>
	<input type="text" name="adulte" id="adulte" value="###value_adulte###" tabindex="7"/>
	<br/>
	<label for="enfant" accesskey="f">nombre d'enfants</label>
	<input type="text" name="enfant" id="enfant" value="###value_enfant###" tabindex="8"/>
	<br/>

	<label for="dejdin" accesskey="t">Quand</label>
	<select name="dejdin" style="width:150px;" tabindex="9">
		<option value="sodi" ###selected_dejdin_sodi###></option>
		<option value="midi" ###selected_dejdin_midi###>Midi</option>
		<option value="soir" ###selected_dejdin_soir###>Soir</option>
		</select>
	<br/>
	<label for="entier" accesskey="r">(avec supplément) salle entière</label>
	<select name="entier" style="width:150px;" tabindex="10">
		<option value="non" ###selected_entier_non###>Non</option>
		<option value="oui" ###selected_entier_oui###>Oui</option>
		</select>
	<br/>
	

	<label for="text" accesskey="c">Votre commentaire</label>
	<textarea cols="50" rows="5" name="text" id="text" style="width:320px;" tabindex="6">###value_text###</textarea>
	<br/>

	<input type="submit" value="Envoyer" tabindex="11"/><br/>
</fieldset>
</form>
<!-- ###TEMPLATE_FORM### end -->



<!-- ###TEMPLATE_EMAIL_RECEIVER_HTML### begin
    OPTIONAL - this will be the email text that is sent to the admin (plaintext!)
    (admin-email = the email you can specify in the mailformplus plugin)
-->
Bonjour, vous avez une demande:<br/>
Qualité: ###topic###<br/>
Nom: ###name###<br/>
Titre ou Société: ###societe###<br/>
Téléphone: ###phone###<br/>
Date: ###date###<br />
nombre d'adultes: ###adulte###<br />
nombre d'enfants: ###enfant###<br />
Quand: ###dejdin###<br />
avec supplément salle entière: ###entier###<br />
Commentaire: ###text###<br/>


<br/>
Adresse email de contact: ###email###<br/>
<!-- ###TEMPLATE_EMAIL_RECEIVER_HTML### end -->

<!-- ###TEMPLATE_ERROR### begin -->
<!-- ###ERROR_START### begin 
this is used for the global error marker ###ERROR### -->
Les informations suivantes sont à renseigner:
<ul>
<!-- ###ERROR_START### end -->


<!-- ###ERROR_END### begin 
this is used for the global error marker ###ERROR### -->
</ul>
<!-- ###ERROR_END### end -->

<!-- ###ERROR_phone### begin -->
<li>Indiquez votre téléphone</li>
<!-- ###ERROR_phone### end -->

<!-- ###ERROR_name### begin -->
<li>Indiquez votre Nom</li>
<!-- ###ERROR_name### end -->

<!-- ###ERROR_email### begin -->
<li>Indiquez votre email</li>
<!-- ###ERROR_email### end -->

<!-- ###TEMPLATE_ERROR### end -->

Il suffit de placer ensuite le plugin dans une page et de le paramétrer

La première fois, j’ai utilisé du typoscript, avec ceci
Voici un extrait de code typoscipt

plugin.tx_thmailformplus_pi1.saveDB = 0

#Qui vous êtes obligatoire
plugin.tx_thmailformplus_pi1.fieldConf.topic {
defaultValue.value = leer
errorCheck = notDefaultValue 
errorText = <li>Vous devez saisir qui vous êtes</li>
}

#Nom obligatoire
plugin.tx_thmailformplus_pi1.fieldConf.name {
errorCheck = required
errorText = <li>Vous devez saisir un nom</li>
}

Avec la nouvelle version, il suffit de renseigner les champs dans Mandatory field (enter name of formular field seperated by ",") pour les champs obligatoires

Si les spammeurs sont de passage, vous pouvez utiliser un captcha

A noter que cette extension n’est plus d’actualité, elle est désormais développée sous mailformplusplus, qui s’appelle maintenant Formhandler.