Ich konnte mich mit meinem Entschluß doch das andere Formular-Modul zu verwenden nicht abfinden und habe jetzt, dank einer guten Freundin, die fertige Lösung meines Problems. Die will ich Euch nicht vorhalten.
Ihr braucht für das Formular mit Captcha (und sogar der Möglichkeit des Dateianhangs) (Ursprung "w3concepts.form.v1"):
- einen Artikel mit dem Formular-Code, z.B.
Code: Alles auswählen
<table border="0" width="100%" align="center">
<tr>
<td valign="top"><font color="#ff9900">Bemerkung:</font></td>
<td>###name:Bemerkung; type:textarea; rows:5; cols:50###</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td valign="top"><font color="#ff9900">Sicherheitscode:</font></td>
<td>
<p><strong>Bitte geben Sie folgenden Sicherheitscode in das Textfeld ein, damit das Formular versendet werden kann.</strong></p>
<p><img src="captcha/captcha.php" border="0" alt="Sicherheitscode" title="Sicherheitscode" width="140" height="40" /> ###name:Sicherheitscode; type:text; size:5###</p>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" value="Abschicken" />
<input type="reset" value="Einträge löschen" />
</td>
</tr>
</table>
- das Kontaktformular-Modul
Input
Code: Alles auswählen
/***********************************************
* CONTENIDO MODUL - INPUT
*
* Modulname : w3concepts.form.v1
* Author : Andreas Kummer
* Copyright : mumprecht & kummer w3concepts
* Created : 20-08-2004
* Modified : 20-08-2004
************************************************/
echo "<table cellspacing=\"0\" cellpadding=\"10\" border=\"0\"><tr valign=\"top\">";
echo "<tr><td class=\"text_medium\">Zieladresse (alias@mydomain.com):</td>";
echo "<td><input type=\"text\" name=\"CMS_VAR[0]\" value=\"CMS_VALUE[0]\" size=\"30\" /></td></tr>";
echo "<tr><td class=\"text_medium\">Betreff:</td>";
echo "<td><input type=\"text\" name=\"CMS_VAR[1]\" value=\"CMS_VALUE[1]\" size=\"30\" /></td></tr>";
echo "<tr><td class=\"text_medium\">Antwortadresse (alias@mydomain.com):</td>";
echo "<td><input type=\"text\" name=\"CMS_VAR[2]\" value=\"CMS_VALUE[2]\" size=\"30\" /></td></tr>";
echo "<tr><td class=\"text_medium\">E-Mailname (z.B. Vorname Name):</td>";
echo "<td><input type=\"text\" name=\"CMS_VAR[3]\" value=\"CMS_VALUE[3]\" size=\"30\" /></td></tr>";
echo "<tr><td class=\"text_medium\">Hintergrundfarbe bei Fehlern (z.B. red):</td>";
echo "<td><input type=\"text\" name=\"CMS_VAR[4]\" value=\"CMS_VALUE[4]\" size=\"30\" /></td></tr>";
echo "</table>";
Output
Code: Alles auswählen
<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname : w3concepts.form.v1
* Author : Andreas Kummer
* Copyright : mumprecht & kummer w3concepts
* Created : 20-08-2004
* Modified : 20-08-2004
************************************************/
#Includes
cInclude("classes", "class.phpmailer.php");
class w3form {
var $email, $aufgedroeselt, $form, $formularFeld, $attachments;
function w3form() {
}
function sendEmail() {
$this->aufdroeseln($this->suppress('sent'));
$this->generateEmailMessage();
mail($this->email['adresses'],$this->email['subject'],$this->email['message'],"From: {$this->email['from']['name']} <{$this->email['from']['email']}>\nReply-To: {$this->email['from']['email']}\nX-Mailer: PHP/" . phpversion());
}
// PRIVATE
# function sendEmail() {
# global $attachments;
# $this->aufdroeseln($this->suppress('sent','anhang[]'));
# $this->generateEmailMessage();
# $mail = new phpmailer;
# $mail->IsSMTP();
# $mail->Host = "localhost";
# $mail->From = $this->email['from']['email'];
# $mail->FromName = $this->email['from']['name'];
# $mail->AddAddress($this->email['adresses']);
# foreach($attachments as $key3 => $value3) { //loop the Attachments to be added …
# $mail->AddAttachment("upload/".$value3);
# }
# $mail->Subject = $this->email['subject'];
# $mail->Body = $this->email['message'];
# $mail->WordWrap = 1000;
# $mail->Send();
# foreach($attachments as $key => $value) {//remove the uploaded files ..
# unlink("upload/".$value);
# }
# }
// PRIVATE
function aufdroeseln($aufzudroeseln,$prefix = '') {
foreach ($aufzudroeseln as $key => $value) {
if (is_array($value)) {
$this->aufdroeseln($value,$key." ");
} else {
$this->aufgedroeselt["{$prefix}{$key}"] = $value;
}
}
}
// PRIVATE
function add2Message($key,$value) {
if (strlen($key) > 25 OR strlen($value) > 54) {
$this->email['message'] .= "$key\n$value\n";
} else {
$this->email['message'] .= $key;
$this->email['message'] .= str_repeat(' ',25-strlen($key));
$this->email['message'] .= "$value\n";
}
}
// PRIVATE
function generateEmailMessage() {
if ($this->aufgedroeselt) foreach ($this->aufgedroeselt as $key => $value) {
$this->add2Message($key,$value);
}
$this->uploadFile();
}
function uploadFile() {
global $attachments;
$attachments = array();
if(count($_FILES[anhang]['name']) > 0) {
while(list($key2,$value2) = each($_FILES[anhang]['name']))
{
if(!empty($value2))
{
$filename = $value2;
//the Array will be used later to attach the files and then remove them from server !
$attachments[] = $filename;
$dir = 'upload/'.$filename;
$success = copy($_FILES[anhang]['tmp_name'][$key2], $dir);
}
}
}
#if ($success) {
# echo "<p>Die Daten wurden erfolgreich hochgeladen.</p>";
#} else {
# echo "<p>Es wurden keine Daten hochgeladen.</p>";
#}
}
// PRIVATE
function suppress() {
$suppress = func_get_args();
foreach ($_POST as $key => $value) {
if (array_search($key,$suppress) === false) $fields[$key] = $value;
}
return $fields;
}
// PUBLIC
function addEmailAdress($email) {
if (empty($this->emailAdresses)) {
$this->email['adresses'] .= "$email";
} else {
$this->email['adresses'] .= ", $email";
}
}
// PUBLIC
function setEmailSubject($subject) {
$this->email['subject'] = $subject;
}
// PUBLIC
function setEmailFrom($email,$name) {
$this->email['from']['email'] = $email;
$this->email['from']['name'] = $name;
}
// PUBLIC
function setForm($form) {
$this->form['form'] = $form;
}
// PUBLIC
function setAnswer($answer) {
$this->form['answer'] = $answer;
}
// PUBLIC
function setBackgroundError($color) {
$this->form['colorError'] = $color;
}
// PRIVATE
function formularInterpretation($formular) {
$felder = split('###',$formular);
for ($i=1;$i<count($felder);$i=$i+2) {
$attributte = split(';',trim($felder[$i]));
foreach ($attributte as $attribut) {
$namewert = split(':',trim($attribut));
if ($namewert[0] != 'option' && $namewert[0] != 'optionvalue') {
$feld["{$felder[$i]}"]["{$namewert[0]}"] = $namewert[1];
} else {
$feld["{$felder[$i]}"]["{$namewert[0]}"][] = $namewert[1];
}
}
}
return $feld;
}
// PRIVATE
function formularAusgabe($sent = false) {
echo '<form action="" method="POST" enctype="multipart/form-data">';
echo '<input type="hidden" name="sent" value="true" />';
$formular = $this->form['form'];
$formulardaten = $this->formularInterpretation($formular);
$formular = split('###',$formular);
foreach ($formular as $formularteil) {
if (!empty($formulardaten["{$formularteil}"])) {
$this->formularFeld($formulardaten["{$formularteil}"],$sent);
} else {
echo $formularteil;
}
}
echo '</form>';
}
// PRIVATE
function formularFeld($attribute,$sent) {
$anhaenge = array();
$parameter = "name=\"{$attribute['name']}\"";
#if ($sent && !$this->formularFeldKorrekt($attribute)) $style ="style=\"background-color:{$this->form['colorError']};\"";
if ($sent && !$this->formularFeldKorrekt($attribute) && $attribute['name'] == 'Sicherheitscode') $style ="style=\"background-color:{$this->form['colorError']};\"";
switch ($attribute['type']) {
case 'select':
case 'password':
case 'file':
case 'text':
if (!empty($attribute['size'])) $parameter .= " size=\"{$attribute['size']}\"";
break;
}
switch ($attribute['type']) {
case 'textarea':
case 'text':
if (!empty($attribute['size'])) $parameter .= " size=\"{$attribute['size']}\"";
if (!empty($attribute['value'])) $value = $attribute['value'];
if (!empty($_POST["{$attribute['name']}"])) $value = $_POST["{$attribute['name']}"];
break;
}
switch ($attribute['type']) {
case 'text':
echo "<input type=\"text\" $parameter value=\"$value\" $style />";
break;
case 'file':
echo "<input type=\"file\" name=\"anhang[]\" $style />";
$anhaenge[] = $attribute['name'];
break;
case 'password':
echo "<input type=\"password\" $parameter value=\"$value\" $style />";
break;
case 'textarea':
echo "<textarea name=\"{$attribute['name']}\" cols=\"";
echo (empty($attribute['cols']))?('20'):($attribute['cols']);
echo "\" rows=\"";
echo (empty($attribute['rows']))?('2'):($attribute['rows']);
echo "\" wrap=\"virtual\" $style>$value</textarea>";
break;
case 'select':
echo "<select $parameter $style>";
for ($i=0;$i<count($attribute['option']);$i++) {
if (!empty($attribute['optionvalue'][$i])) {
if (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $attribute['optionvalue'][$i]) {
echo "<option value=\"{$attribute['optionvalue'][$i]}\" selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
if (empty($_POST["{$attribute['name']}"]) && !empty($attribute['optionvalue'][$i]) && $attribute['optionvalue'][$i] == $attribute['value']) {
echo "<option value=\"{$attribute['optionvalue'][$i]}\" selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
echo "<option value=\"{$attribute['optionvalue'][$i]}\">{$attribute['option'][$i]}</option>\n";
}
}
} else {
if (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $attribute['option'][$i]) {
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
if (empty($_POST["{$attribute['name']}"]) && $attribute['option'][$i] == $attribute['value']) {
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
echo "<option>{$attribute['option'][$i]}</option>\n";
}
}
}
}
echo "</select>";
break;
case 'checkbox':
$formularbezeichner = preg_split('[\[|\]]',$attribute['name']);
if ($sent) {
if ($_POST["{$formularbezeichner[0]}"]["{$formularbezeichner[1]}"] == $attribute['value']) {
#if (array_search($attribute['value'], $_POST[$formularbezeichner[0]])) {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/>";
}
} else {
if (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/>";
}
}
break;
case 'radio':
if (!empty($_POST["{$attribute['name']}"])) {
if ($_POST["{$attribute['name']}"] == $attribute['value']) {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" />";
}
} else {
if (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\"/>";
}
}
break;
}
}
// PRIVATE
function formularVollstaendig() {
$formular = $this->form['form'];
$felder = $this->formularInterpretation($formular);
foreach ($felder as $feld) {
if (!$this->formularFeldKorrekt($feld)) return false;
}
return true;
}
// PRIVATE
function success() {
$this->sendEmail();
echo $this->form['answer'];
}
// PRIVATE
function formularFeldKorrekt($feld) {
// schauen, ob sicherheitscode richtig ist
if(!$_SESSION['captcha_spam'] OR $_POST["Sicherheitscode"] != $_SESSION['captcha_spam']) return false;
// prüfung, ob pflichtfeld vorhanden
# if (!empty($feld['mandatory']) && $feld['mandatory'] == 'true' && empty($_POST["{$feld['name']}"])) return false;
// wenn das formularfeld kein pflichtfeld und nicht vorhanden ist, true zurück geben
# if (empty($_POST["{$feld['name']}"])) return true;
// regular expression prüfungen
# if (!empty($feld['valid']) && $feld['valid'] == 'simpletext' && !eregi("^[öäüéàèâêîça-z-]*$",$_POST["{$feld['name']}"])) return false;
# if (!empty($feld['valid']) && $feld['valid'] == 'text' && !eregi("^[ .,;!?()öäüéàèâêîça-z-]*$",$_POST["{$feld['name']}"])) return false;
# if (!empty($feld['valid']) && $feld['valid'] == 'integer' && !eregi("^[0-9]*$",$_POST["{$feld['name']}"])) return false;
# if (!empty($feld['valid']) && $feld['valid'] == 'float' && !eregi("^[0-9]*[.]{0,1}[0-9]*$",$_POST["{$feld['name']}"])) return false;
# if (!empty($feld['valid']) && $feld['valid'] == 'date' && !eregi("^[0-9]{1,2}.[0-9]{1,2}.[0-9]{2}$",$_POST["{$feld['name']}"])) return false;
# if (!empty($feld['valid']) && $feld['valid'] == 'email' && !eregi("^[öäüéàèâêîç_a-z0-9-]+(\.[öäüéàèâêîç_a-z0-9-]+)*@[öäüéàèâêîça-z0-9-]+(\.[öäüéàèâêîça-z0-9-]+)*$",$_POST["{$feld['name']}"])) return false;
// grössenbereich bei integer und float prüfen
# if (!empty($feld['minvalue']) && $_POST["{$feld['name']}"] < $feld['minvalue']) return false;
# if (!empty($feld['maxvalue']) && $_POST["{$feld['name']}"] > $feld['maxvalue']) return false;
// längenbereich bei allen typen prüfen
# if (!empty($feld['minlength']) && strlen($_POST["{$feld['name']}"]) < $feld['minlength']) return false;
# if (!empty($feld['maxlength']) && strlen($_POST["{$feld['name']}"]) > $feld['maxlength']) return false;
return true;
}
//PUBLIC
function process() {
if (!isset($_POST['sent'])) {
$this->formularAusgabe();
} elseif ($this->formularVollstaendig()) {
$this->success();
} else {
echo ' <font color="red">Sie haben den Sicherheitscode nicht richtig eingegeben. Bitte überprüfen Sie Ihre Angabe nocheinmal.<br></font>';
$this->formularAusgabe(true);
}
}
}
if ($edit) {
echo "<h1>Formularkonfiguration</h1>";
echo "<p>Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:</p>";
echo "CMS_HTML[0]";
echo "<p>Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich prozessiert worden ist:</p>";
echo "CMS_HTML[1]";
} else {
$formular = new w3form();
$formular->addEmailAdress("CMS_VALUE[0]");
$formular->setEmailSubject("CMS_VALUE[1]");
$formular->setEmailFrom("CMS_VALUE[2]","CMS_VALUE[3]");
$formular->setBackgroundError("CMS_VALUE[4]");
$formular->setForm("CMS_HTML[0]");
$formular->setAnswer("CMS_HTML[1]");
$formular->process();
}
?>
- ein Template, dass das Kontaktformular-Modul enthält
- ein "Snippet", dass den Code
im Head-Bereich der Ausgabe einfügt. (Wie man ein Snippet einbaut, könnt ihr
hier lesen.)
- und dann noch die 3 wichtigen Dateien für das Captcha selbst. Die könnt ihr Euch hier downloaden:
-
captcha.php
-
captcha.PNG
-
XFILES.TTF
Diese speichert ihr in einen Ordner "captcha" und ladet sie per FTP ins "cms"-Verzeichnis.
Ich hoffe, ich kann damit nun auch anderen helfen. Viel Erfolg beim Probieren.