ich hatte das Problem das ich auf der Webseite verschiedene Kontaktformulare brauche - je nachdem welche Anfrage der Kunde hat. Ich wollte nicht für jede verschiedene Anfrageart neue Templates erstellen, insofern habe ich das Kontaktformular umgeschrieben und kann nun im Backend entsprechend der Anfrage konfiguriert werden.
Pflichfelder können einfach angehakt werden. Jedes Feld kann ein Pflichtfeld sein.
Das Formulat enthält:
- max. 10 Textfelder
max. 3 Textareas
max. 3 Ja/Nein Felder
Soweit alles klar???

Der INPUT-Teil:
Code: Alles auswählen
?><?php
/***********************************************
* CONTENIDO MODUL - INPUT
*
* Modulname : Contact form *plus*
* Author(s) : Andreas Lindner, Milly
* Created : 12.08.2005
* Modified : 01.04.2008
************************************************/
?>
<table border="0">
<tr>
<td><?php echo mi18n("Absender EMail");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[0]";?>" value="<?php echo "CMS_VALUE[0]"; ?>"></td>
</tr><tr>
<td><?php echo mi18n("Absender Name");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[2]";?>" value="<?php echo "CMS_VALUE[2]"; ?>"></td>
</tr><tr>
<td><?php echo mi18n("Empfänger EMail");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[1]";?>" value="<?php echo "CMS_VALUE[1]"; ?>"></td>
</tr><tr>
<td><?php echo mi18n("Betreff");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[3]";?>" value="<?php echo "CMS_VALUE[3]"; ?>"></td>
</tr>
<?php
$c1 = '';
$c2 = '';
$c3 = '';
$c4 = '';
switch (strtolower("CMS_VALUE[4]")) {
case "smtp" :
$c1 = ' checked';
break;
case "mail" :
$c2 = ' checked';
break;
case "sendmail" :
$c3 = ' checked';
break;
case "qmail" :
$c4 = ' checked';
break;
default :
$c3 = ' checked';
}
?>
<tr>
<td valign="top"><?php echo mi18n("Mailer");?></td>
<td>
<input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="mail"<?php echo $c2;?>> <?php echo mi18n("mail");?><br/>
<input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="qmail"<?php echo $c4;?>> <?php echo mi18n("qmail");?><br/>
<input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="sendmail"<?php echo $c3;?>> <?php echo mi18n("sendmail");?><br/>
<input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="smtp"<?php echo $c1;?>> <?php echo mi18n("smtp");?><br/>
</td>
</tr><tr>
<td><?php echo mi18n("SMTP Host");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[5]";?>" value="<?php echo "CMS_VALUE[5]"; ?>"></td>
</tr><tr>
<td><?php echo mi18n("SMTP User");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[6]";?>" value="<?php echo "CMS_VALUE[6]"; ?>"></td>
</tr><tr>
<td><?php echo mi18n("SMTP Passwort");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[7]";?>" value="<?php echo "CMS_VALUE[7]"; ?>"></td>
</tr><tr>
<td colspan="2"><?php echo mi18n("Felder");?><br>
<?php
if (strtolower("CMS_VALUE[9]") == "t1") { $t1 = ' checked'; } else { $t1 = ''; }
if (strtolower("CMS_VALUE[11]") == "t2") { $t2 = ' checked'; } else { $t2 = ''; }
if (strtolower("CMS_VALUE[13]") == "t3") { $t3 = ' checked'; } else { $t3 = ''; }
if (strtolower("CMS_VALUE[15]") == "t4") { $t4 = ' checked'; } else { $t4 = ''; }
if (strtolower("CMS_VALUE[17]") == "t5") { $t5 = ' checked'; } else { $t5 = ''; }
if (strtolower("CMS_VALUE[19]") == "t6") { $t6 = ' checked'; } else { $t6 = ''; }
if (strtolower("CMS_VALUE[21]") == "t7") { $t7 = ' checked'; } else { $t7 = ''; }
if (strtolower("CMS_VALUE[23]") == "t8") { $t8 = ' checked'; } else { $t8 = ''; }
if (strtolower("CMS_VALUE[25]") == "t9") { $t9 = ' checked'; } else { $t9 = ''; }
if (strtolower("CMS_VALUE[27]") == "t10") { $t10 = ' checked'; } else { $t10 = ''; }
if (strtolower("CMS_VALUE[29]") == "a1") { $a1 = ' checked'; } else { $a1 = ''; }
if (strtolower("CMS_VALUE[31]") == "a2") { $a2 = ' checked'; } else { $a2 = ''; }
if (strtolower("CMS_VALUE[33]") == "a3") { $a3 = ' checked'; } else { $a3 = ''; }
if (strtolower("CMS_VALUE[35]") == "j1") { $j1 = ' checked'; } else { $j1 = ''; }
if (strtolower("CMS_VALUE[37]") == "j2") { $j2 = ' checked'; } else { $j2 = ''; }
if (strtolower("CMS_VALUE[39]") == "j3") { $j3 = ' checked'; } else { $j3 = ''; }
?>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>Text 01</td><td><input type="text" name="<?php echo "CMS_VAR[8]";?>" value="<?php echo "CMS_VALUE[8]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[9]";?>" value="t1"<?php echo $t1;?>>Pfl.</td>
</tr><tr>
<td>Text 02</td><td><input type="text" name="<?php echo "CMS_VAR[10]";?>" value="<?php echo "CMS_VALUE[10]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[11]";?>" value="t2"<?php echo $t2;?>>Pfl.</td>
</tr><tr>
<td>Text 03</td><td><input type="text" name="<?php echo "CMS_VAR[12]";?>" value="<?php echo "CMS_VALUE[12]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[13]";?>" value="t3"<?php echo $t3;?>>Pfl.</td>
</tr><tr>
<td>Text 04</td><td><input type="text" name="<?php echo "CMS_VAR[14]";?>" value="<?php echo "CMS_VALUE[14]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[15]";?>" value="t4"<?php echo $t4;?>>Pfl.</td>
</tr><tr>
<td>Text 05</td><td><input type="text" name="<?php echo "CMS_VAR[16]";?>" value="<?php echo "CMS_VALUE[16]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[17]";?>" value="t5"<?php echo $t5;?>>Pfl.</td>
</tr><tr>
<td>Text 06</td><td><input type="text" name="<?php echo "CMS_VAR[18]";?>" value="<?php echo "CMS_VALUE[18]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[19]";?>" value="t6"<?php echo $t6;?>>Pfl.</td>
</tr><tr>
<td>Text 07</td><td><input type="text" name="<?php echo "CMS_VAR[20]";?>" value="<?php echo "CMS_VALUE[20]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[21]";?>" value="t7"<?php echo $t7;?>>Pfl.</td>
</tr><tr>
<td>Text 08</td><td><input type="text" name="<?php echo "CMS_VAR[22]";?>" value="<?php echo "CMS_VALUE[22]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[23]";?>" value="t8"<?php echo $t8;?>>Pfl.</td>
</tr><tr>
<td>Text 09</td><td><input type="text" name="<?php echo "CMS_VAR[24]";?>" value="<?php echo "CMS_VALUE[24]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[25]";?>" value="t9"<?php echo $t9;?>>Pfl.</td>
</tr><tr>
<td>Text 10</td><td><input type="text" name="<?php echo "CMS_VAR[26]";?>" value="<?php echo "CMS_VALUE[26]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[27]";?>" value="t10"<?php echo $t10;?>>Pfl.</td>
</tr><tr>
<td>Area 1</td><td><input type="text" name="<?php echo "CMS_VAR[28]";?>" value="<?php echo "CMS_VALUE[28]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[29]";?>" value="a1"<?php echo $a1;?>>Pfl.</td>
</tr><tr>
<td>Area 2</td><td><input type="text" name="<?php echo "CMS_VAR[30]";?>" value="<?php echo "CMS_VALUE[30]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[31]";?>" value="a2"<?php echo $a2;?>>Pfl.</td>
</tr><tr>
<td>Area 3</td><td><input type="text" name="<?php echo "CMS_VAR[32]";?>" value="<?php echo "CMS_VALUE[32]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[33]";?>" value="a3"<?php echo $a3;?>>Pfl.</td>
</tr><tr>
<td>J/N 1</td><td><input type="text" name="<?php echo "CMS_VAR[34]";?>" value="<?php echo "CMS_VALUE[34]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[35]";?>" value="j1"<?php echo $j1;?>>Pfl.</td>
</tr><tr>
<td>J/N 2</td><td><input type="text" name="<?php echo "CMS_VAR[36]";?>" value="<?php echo "CMS_VALUE[36]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[37]";?>" value="j2"<?php echo $j2;?>>Pfl.</td>
</tr><tr>
<td>J/N 3</td><td><input type="text" name="<?php echo "CMS_VAR[38]";?>" value="<?php echo "CMS_VALUE[38]"; ?>"></td>
<td><input type="checkbox" name="<?php echo "CMS_VAR[39]";?>" value="j3"<?php echo $j3;?>>Pfl.</td>
</tr>
</table></td>
</tr>
</table>
<?php
Code: Alles auswählen
<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname : Contact form *plus*
* Author(s) : Andreas Lindner, Milly
* Created : 12.08.2005
* Modified : 01.04.2008
************************************************/
#Includes
cInclude("classes", "class.phpmailer.php");
if (!isset ($_POST['send'])) {
#Form has not been sent yet
cInclude('classes', 'class.article.php');
cInclude('classes', 'class.template.php');
#Create contact form
echo '<div class="kontaktformular"/>';
echo '<form name="kontaktform" id="kontaktform" method="post" action="'.$sess->url("front_content.php?idcat=$idcat&idart=$idart&parentid=$parentid").'">'."\n";
echo '<input type="hidden" name="send" value="1">';
echo "<p align=\"center\">\n";
echo "<table border=\"0\" cellpadding=\"4\" cellspacing=\"4\">\n";
#Textfields
if (strlen("CMS_VALUE[8]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[8]";
if (strtolower("CMS_VALUE[9]") == "t1") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld1\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
if (strlen("CMS_VALUE[10]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[10]";
if (strtolower("CMS_VALUE[11]") == "t2") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld2\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
if (strlen("CMS_VALUE[12]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[12]";
if (strtolower("CMS_VALUE[13]") == "t3") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld3\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
if (strlen("CMS_VALUE[14]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[14]";
if (strtolower("CMS_VALUE[15]") == "t4") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld4\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
if (strlen("CMS_VALUE[16]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[16]";
if (strtolower("CMS_VALUE[17]") == "t5") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld5\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
if (strlen("CMS_VALUE[18]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[18]";
if (strtolower("CMS_VALUE[19]") == "t6") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld6\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
if (strlen("CMS_VALUE[20]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[20]";
if (strtolower("CMS_VALUE[21]") == "t7") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld7\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
if (strlen("CMS_VALUE[22]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[22]";
if (strtolower("CMS_VALUE[23]") == "t8") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld8\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
if (strlen("CMS_VALUE[24]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[24]";
if (strtolower("CMS_VALUE[25]") == "t9") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld9\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
if (strlen("CMS_VALUE[26]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[26]";
if (strtolower("CMS_VALUE[27]") == "t10") { echo " (*)"; }
echo "</td><td>";
echo "<input type=\"text\" name=\"textfeld10\" class=\"eingabe\" maxlength=\"100\"></td></tr>\n"; }
#Textareas
if (strlen("CMS_VALUE[28]") > 2)
{ echo "<tr><td valign=\"top\" align=\"right\">" . "CMS_VALUE[28]";
if (strtolower("CMS_VALUE[29]") == "a1") { echo " (*)"; }
echo "</td><td>";
echo "<textarea name=\"textarea1\"></textarea></td></tr>\n"; }
if (strlen("CMS_VALUE[30]") > 2)
{ echo "<tr><td valign=\"top\" align=\"right\">" . "CMS_VALUE[30]";
if (strtolower("CMS_VALUE[31]") == "a2") { echo " (*)"; }
echo "</td><td>";
echo "<textarea name=\"textarea2\"></textarea></td></tr>\n"; }
if (strlen("CMS_VALUE[32]") > 2)
{ echo "<tr><td valign=\"top\" align=\"right\">" . "CMS_VALUE[32]";
if (strtolower("CMS_VALUE[33]") == "a3") { echo " (*)"; }
echo "</td><td>";
echo "<textarea name=\"textarea3\"></textarea></td></tr>\n"; }
#J/N-Fields
if (strlen("CMS_VALUE[34]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[34]";
if (strtolower("CMS_VALUE[35]") == "j1") { echo " (*)"; }
echo "</td><td align=\"center\">";
echo "<input type=\"radio\" name=\"jnfield1\" value=\"ja\"> Ja ";
echo "<input type=\"radio\" name=\"jnfield1\" value=\"nein\"> Nein</td></tr>\n"; }
if (strlen("CMS_VALUE[36]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[36]";
if (strtolower("CMS_VALUE[37]") == "j1") { echo " (*)"; }
echo "</td><td align=\"center\">";
echo "<input type=\"radio\" name=\"jnfield2\" value=\"ja\"> Ja ";
echo "<input type=\"radio\" name=\"jnfield2\" value=\"nein\"> Nein</td></tr>\n"; }
if (strlen("CMS_VALUE[38]") > 2)
{ echo "<tr><td align=\"right\">" . "CMS_VALUE[38]";
if (strtolower("CMS_VALUE[39]") == "j1") { echo " (*)"; }
echo "</td><td align=\"center\">";
echo "<input type=\"radio\" name=\"jnfield3\" value=\"ja\"> Ja ";
echo "<input type=\"radio\" name=\"jnfield3\" value=\"nein\"> Nein</td></tr>\n"; }
echo "<tr><td align=\"center\">";
echo "<br><input type=\"submit\" value=\"Absenden\">";
echo "</td><td align=\"center\">";
echo "<br><input type=\"reset\" value=\"Löschen\"></td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"right\">(*) Pflichtfelder</td></tr>\n";
echo "</table></p>\n";
echo "</form></div>\n";
} elseif ($_POST['send'] == 1) {
#Form has been sent
#Check user input
$noerrors = true;
if (strlen("CMS_VALUE[8]") > 2 && strtolower("CMS_VALUE[9]") == "t1" && $_POST['textfeld1'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[10]") > 2 && strtolower("CMS_VALUE[11]") == "t2" && $_POST['textfeld2'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[12]") > 2 && strtolower("CMS_VALUE[13]") == "t3" && $_POST['textfeld3'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[14]") > 2 && strtolower("CMS_VALUE[15]") == "t4" && $_POST['textfeld4'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[16]") > 2 && strtolower("CMS_VALUE[17]") == "t5" && $_POST['textfeld5'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[18]") > 2 && strtolower("CMS_VALUE[19]") == "t6" && $_POST['textfeld6'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[20]") > 2 && strtolower("CMS_VALUE[21]") == "t7" && $_POST['textfeld7'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[22]") > 2 && strtolower("CMS_VALUE[23]") == "t8" && $_POST['textfeld8'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[24]") > 2 && strtolower("CMS_VALUE[25]") == "t9" && $_POST['textfeld9'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[26]") > 2 && strtolower("CMS_VALUE[27]") == "t10" && $_POST['textfeld10'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[28]") > 2 && strtolower("CMS_VALUE[29]") == "a1" && $_POST['textarea1'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[30]") > 2 && strtolower("CMS_VALUE[31]") == "a2" && $_POST['textarea2'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[32]") > 2 && strtolower("CMS_VALUE[33]") == "a3" && $_POST['textarea3'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[34]") > 2 && strtolower("CMS_VALUE[35]") == "j1" && $_POST['jnfield1'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[36]") > 2 && strtolower("CMS_VALUE[37]") == "j2" && $_POST['jnfield2'] == '') { $noerrors = false; }
if (strlen("CMS_VALUE[38]") > 2 && strtolower("CMS_VALUE[39]") == "j3" && $_POST['jnfield3'] == '') { $noerrors = false; }
if ($noerrors == false) {
echo "<p>";
#Errors have been found
echo mi18n("Leider konnte Ihre eMail nicht abgesendet werden! Überprüfen Sie bitte ob Sie alle relevanten Felder ausgefüllt haben und ob Ihre eingegebene eMail-Adresse gültig ist.")."<br/><br/>";
echo '<a href="javascript:history.back();">‹ '.mi18n("zurück").'</a>';
} else {
#No errors, create and send mail
$mail = new phpmailer;
$mail_body = "<html><head></head><body bgcolor=\"#ffffff\"><table cellspacing=\"0\" cellpadding=\"2\" border=\"0\">\n";
if (is_array($_POST)) {
foreach ($_POST as $key => $value) {
if ($key != 'send') {
$mail_body .= "<tr><td>$key</td><td>$value</td></tr>";
}
}
}
$mail_body .= "</table></body></html>\n";
$mail->Host = "localhost";
$mail->IsHTML(true);
#Get mailer from settings
switch (strtolower("CMS_VALUE[4]")) {
case "smtp" :
$mail->IsSMTP();
$host = "CMS_VALUE[5]";
$user = "CMS_VALUE[6]";
$password = "CMS_VALUE[7]";
if (($host != '') && ($user != '') && ($password != '')) {
$mail-> $SMTPAuth = true;
$mail->Host = $host;
$mail->Username = $user;
$mail->Password = $password;
}
break;
case "mail" :
$mail->IsMail();
break;
case "sendmail" :
$mail->IsSendmail();
break;
case "qmail" :
$mail->IsQmail();
break;
default :
}
$mail->From = "CMS_VALUE[0]";
$mail->FromName = "CMS_VALUE[2]";
$mail->AddAddress("CMS_VALUE[1]", "");
$mail->Subject = "CMS_VALUE[3]";
$mail->Body = $mail_body;
$mail->WordWrap = 50;
$mail->Send();
#Display message after mail is sent
echo mi18n("Ihre eMail wurde uns übermittelt.<br><br>Vielen Dank!")."<br/>";
}
}
?>
Die CSS-Klassen zum anpassen sind "kontaktformular" für das Formular und "eingabe" für die Eingabefelder.
Viel Spaß damit
Milly