updates for V1.0.0
Dieser Commit ist enthalten in:
Ursprung
381994a727
Commit
cb6d0140a7
3 geänderte Dateien mit 162 neuen und 515 gelöschten Zeilen
11
README.md
11
README.md
|
@ -1,3 +1,10 @@
|
||||||
# module-cl-contactform
|
# Module CL Contact Form
|
||||||
|
|
||||||
contactform module based on w3concepts.form.v1
|
contact form module based on module w3concepts.form.v1.
|
||||||
|
|
||||||
|
I'm still working on new documentation. Meanwhile, you may use the documentation from original module.
|
||||||
|
See https://forum.contenido.org/viewtopic.php?f=110&t=5066&hilit=w3concepts.form.v1
|
||||||
|
|
||||||
|
If you want to use captcha, you need to download securimage 4.0.2 and install it in folder cms/securimage
|
||||||
|
Download https://github.com/dapphp/securimage/releases/tag/4.0.2
|
||||||
|
Be aware that this version may not be compatible to PHP 8.x. I am working on a compatible version.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
<modulepackage><package_guid/>
|
<modulepackage><package_guid/>
|
||||||
<package_data/>
|
<package_data/>
|
||||||
<module><name>CL Contactform</name>
|
<module><name>CL Contact Form</name>
|
||||||
<description><Ihre Modulbeschreibung>
|
<description><Ihre Modulbeschreibung>
|
||||||
|
|
||||||
Autor:
|
Autor:
|
||||||
|
@ -9,8 +9,9 @@ Version:</description>
|
||||||
<type>Content</type>
|
<type>Content</type>
|
||||||
<input>?><?php
|
<input>?><?php
|
||||||
/**
|
/**
|
||||||
* Module cl-contactform input
|
* Module cl-contact_form input
|
||||||
*
|
*
|
||||||
|
* @package module/cl_contact_form
|
||||||
* @author Ortwin Pinke <info@php-backoffice.de>
|
* @author Ortwin Pinke <info@php-backoffice.de>
|
||||||
*
|
*
|
||||||
* based on w3concepts.form.v1 from Andreas Kummer (2004-08-20)
|
* based on w3concepts.form.v1 from Andreas Kummer (2004-08-20)
|
||||||
|
@ -18,47 +19,67 @@ Version:</description>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
cInclude('frontend', 'includes/class.input.helper.php');
|
cInclude('frontend', 'includes/class.input.helper.php');
|
||||||
$oCfgTable = new UI_Config_Table();
|
$uiConfigTable = new UI_Config_Table();
|
||||||
|
|
||||||
$oField = new cHTMLTextbox("CMS_VAR[0]", "CMS_VALUE[0]");
|
$htmlField = new cHTMLSelectElement("CMS_VAR[10]", 200);
|
||||||
$oField->setWidth(30);
|
$htmlField->autoFill([
|
||||||
$oCfgTable->setCell(0, 0, mi18n("Zieladresse (alias@mydomain.com):"));
|
'null' => mi18n("Bitte wählen"),
|
||||||
$oCfgTable->setCell(0, 1, $oField->render());
|
'mail' => mi18n("Mail (PHP)"),
|
||||||
|
'sendmail' => mi18n("Sendmail"),
|
||||||
|
'smtp' => mi18n("SMTP"),
|
||||||
|
'smtp_auth' => mi18n("SMTP mit oAuth")
|
||||||
|
]);
|
||||||
|
$htmlField->setDefault("CMS_VALUE[10]");
|
||||||
|
$uiConfigTable->setRowCell(0, mi18n("Versand mit:"));
|
||||||
|
$uiConfigTable->setRowCell(1, $htmlField->render());
|
||||||
|
$uiConfigTable->nextRow();
|
||||||
|
|
||||||
$oField = new cHTMLTextbox("CMS_VAR[1]", "CMS_VALUE[1]");
|
$htmlField = new cHTMLTextbox("CMS_VAR[0]", "CMS_VALUE[0]");
|
||||||
$oField->setWidth(30);
|
$htmlField->setWidth(30);
|
||||||
$oCfgTable->setCell(1, 0, mi18n("Betreff:"));
|
$uiConfigTable->setRowCell(0, mi18n("Zieladresse (alias@mydomain.com):"));
|
||||||
$oCfgTable->setCell(1, 1, $oField->render());
|
$uiConfigTable->setRowCell(1, $htmlField->render());
|
||||||
|
$uiConfigTable->nextRow();
|
||||||
|
|
||||||
$oField = new cHTMLTextbox("CMS_VAR[2]", "CMS_VALUE[2]");
|
$htmlField = new cHTMLTextbox("CMS_VAR[1]", "CMS_VALUE[1]");
|
||||||
$oField->setWidth(30);
|
$htmlField->setWidth(30);
|
||||||
$oCfgTable->setCell(2, 0, mi18n("Antwortadresse (alias@mydomain.com):"));
|
$uiConfigTable->setRowCell(0, mi18n("Betreff:"));
|
||||||
$oCfgTable->setCell(2, 1, $oField->render());
|
$uiConfigTable->setRowCell(1, $htmlField->render());
|
||||||
|
$uiConfigTable->nextRow();
|
||||||
|
|
||||||
$oField = new cHTMLTextbox("CMS_VAR[3]", "CMS_VALUE[3]");
|
$htmlField = new cHTMLTextbox("CMS_VAR[2]", "CMS_VALUE[2]");
|
||||||
$oField->setWidth(30);
|
$htmlField->setWidth(30);
|
||||||
$oCfgTable->setCell(3, 0, mi18n("Emailname (z.B. Vorname Name):"));
|
$uiConfigTable->setRowCell(0, mi18n("Antwortadresse (alias@mydomain.com):"));
|
||||||
$oCfgTable->setCell(3, 1, $oField->render());
|
$uiConfigTable->setRowCell(1, $htmlField->render());
|
||||||
|
$uiConfigTable->nextRow();
|
||||||
|
|
||||||
$oField = new cHTMLTextbox("CMS_VAR[4]", "CMS_VALUE[4]");
|
$htmlField = new cHTMLTextbox("CMS_VAR[3]", "CMS_VALUE[3]");
|
||||||
$oField->setWidth(8);
|
$htmlField->setWidth(30);
|
||||||
$oCfgTable->setCell(4, 0, mi18n("Hintergrundfarbe bei Fehlern (z.B. red):"));
|
$uiConfigTable->setRowCell(0, mi18n("Emailname (z.B. Vorname Name):"));
|
||||||
$oCfgTable->setCell(4, 1, $oField->render());
|
$uiConfigTable->setRowCell(1, $htmlField->render());
|
||||||
$oCfgTable->render(true);
|
$uiConfigTable->nextRow();
|
||||||
|
|
||||||
|
$htmlField = new cHTMLTextbox("CMS_VAR[4]", "CMS_VALUE[4]");
|
||||||
|
$htmlField->setWidth(8);
|
||||||
|
$uiConfigTable->setRowCell(0, mi18n("Hintergrundfarbe bei Fehlern (z.B. red):"));
|
||||||
|
$uiConfigTable->setRowCell(1, $htmlField->render());
|
||||||
|
$uiConfigTable->nextRow();
|
||||||
|
|
||||||
|
$uiConfigTable->render(true);
|
||||||
|
|
||||||
?><?php</input>
|
?><?php</input>
|
||||||
<output><?php
|
<output><?php
|
||||||
|
|
||||||
|
global $sess;
|
||||||
/**
|
/**
|
||||||
* Module cl-contactform output
|
* Module cl-contact_form output
|
||||||
*
|
*
|
||||||
|
* @package module/cl_contact_form
|
||||||
* @author Ortwin Pinke <info@php-backoffice.de>
|
* @author Ortwin Pinke <info@php-backoffice.de>
|
||||||
*
|
*
|
||||||
* based on w3concepts.form.v1 from Andreas Kummer (2004-08-20)
|
* based on w3concepts.form.v1 from Andreas Kummer (2004-08-20)
|
||||||
* modified and adapted to Contenido 4.8 under PHP 5.x by Murat Purc (2013-08-24)
|
* modified and adapted to Contenido 4.8 under PHP 5.x by Murat Purc (2013-08-24)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use PHPMailer\PHPMailer\PHPMailer;
|
|
||||||
|
|
||||||
$sFrontEndPath = cRegistry::getClientConfig(cRegistry::getClientId())['path']['frontend'] . 'securimage' . DIRECTORY_SEPARATOR;
|
$sFrontEndPath = cRegistry::getClientConfig(cRegistry::getClientId())['path']['frontend'] . 'securimage' . DIRECTORY_SEPARATOR;
|
||||||
$captchaInstalled = false;
|
$captchaInstalled = false;
|
||||||
if (is_readable($sFrontEndPath)) {
|
if (is_readable($sFrontEndPath)) {
|
||||||
|
@ -68,14 +89,15 @@ if (is_readable($sFrontEndPath)) {
|
||||||
$captchaInstalled = true;
|
$captchaInstalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class w3form
|
class FormGenerator
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public $emailAdresses;
|
||||||
private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => ''];
|
private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => ''];
|
||||||
private array $unraveled = [];
|
private array $unraveled = [];
|
||||||
private array $form = ['form' => '', 'answer' => '', 'colorError' => ''];
|
private array $form = ['form' => '', 'answer' => '', 'colorError' => ''];
|
||||||
|
|
||||||
public function __construct(private bool $captchaInstalled)
|
public function __construct(private bool $captchaInstalled, private cSession $cSession)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -85,18 +107,22 @@ class w3form
|
||||||
$this->unravel($this->suppress('sent'));
|
$this->unravel($this->suppress('sent'));
|
||||||
$this->generateEmailMessage();
|
$this->generateEmailMessage();
|
||||||
|
|
||||||
$oMailer = new PHPMailer();
|
$phpMailer = new \PHPMailer\PHPMailer\PHPMailer(true);
|
||||||
$oMailer->CharSet = "UTF-8";
|
$phpMailer->isMail();
|
||||||
$oMailer->AddAddress($this->email['adresses']);
|
$phpMailer->isHTML(false);
|
||||||
$oMailer->From = $this->email['from']['email'];
|
$phpMailer->CharSet = "UTF-8";
|
||||||
$oMailer->FromName = $this->email['from']['name'];
|
$phpMailer->AddAddress($this->email['adresses']);
|
||||||
$oMailer->Subject = $this->email['subject'];
|
$phpMailer->setFrom($this->email['from']['email'], $this->email['from']['name']);
|
||||||
$oMailer->Body = $this->email['message'];
|
$phpMailer->Subject = $this->email['subject'];
|
||||||
|
$phpMailer->Body = $this->email['message'];
|
||||||
|
|
||||||
if ($oMailer->send()) {
|
try {
|
||||||
|
if ($phpMailer->send()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch (\PHPMailer\PHPMailer\Exception $e) {
|
||||||
|
echo $e->errorMessage();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +139,7 @@ class w3form
|
||||||
|
|
||||||
private function add2Message($key, $value): void
|
private function add2Message($key, $value): void
|
||||||
{
|
{
|
||||||
if (strlen($key) > 25 or strlen($value) > 54) {
|
if (strlen($key) > 25 || strlen($value) > 54) {
|
||||||
$this->email['message'] .= "$key\n$value\n";
|
$this->email['message'] .= "$key\n$value\n";
|
||||||
} else {
|
} else {
|
||||||
$this->email['message'] .= $key;
|
$this->email['message'] .= $key;
|
||||||
|
@ -124,18 +150,16 @@ class w3form
|
||||||
|
|
||||||
private function generateEmailMessage(): void
|
private function generateEmailMessage(): void
|
||||||
{
|
{
|
||||||
if ($this->unraveled)
|
|
||||||
foreach ($this->unraveled as $key => $value) {
|
foreach ($this->unraveled as $key => $value) {
|
||||||
$this->add2Message($key, $value);
|
$this->add2Message($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function suppress(): array
|
private function suppress(...$suppress): array
|
||||||
{
|
{
|
||||||
$fields = [];
|
$fields = [];
|
||||||
$suppress = func_get_args();
|
|
||||||
foreach ($_POST as $key => $value) {
|
foreach ($_POST as $key => $value) {
|
||||||
if (array_search($key, $suppress) === false)
|
if (!in_array($key, $suppress))
|
||||||
$fields[$key] = $value;
|
$fields[$key] = $value;
|
||||||
}
|
}
|
||||||
return $fields;
|
return $fields;
|
||||||
|
@ -180,8 +204,9 @@ class w3form
|
||||||
{
|
{
|
||||||
$fields = explode('###', $form);
|
$fields = explode('###', $form);
|
||||||
$field = [];
|
$field = [];
|
||||||
|
$fieldsCount = count($fields);
|
||||||
|
|
||||||
for ($i = 1; $i < count($fields); $i = $i + 2) {
|
for ($i = 1; $i < $fieldsCount; $i += 2) {
|
||||||
$attribute = explode(';', trim($fields[$i]));
|
$attribute = explode(';', trim($fields[$i]));
|
||||||
foreach ($attribute as $attribute) {
|
foreach ($attribute as $attribute) {
|
||||||
$nameValue = explode(':', trim($attribute));
|
$nameValue = explode(':', trim($attribute));
|
||||||
|
@ -198,7 +223,8 @@ class w3form
|
||||||
|
|
||||||
public function formOutput($sent = false): void
|
public function formOutput($sent = false): void
|
||||||
{
|
{
|
||||||
echo '<div class="textItem secondItem"><form action="" method="POST" class="form-horizontal">';
|
$form_action = $this->cSession->url('front_content.php?idcat=' . cRegistry::getCategoryId() . '&idart=' . cRegistry::getArticleId());
|
||||||
|
echo '<form action="' . $form_action . '" method="post" class="form-horizontal">';
|
||||||
echo '<input type="hidden" name="sent" value="true" />';
|
echo '<input type="hidden" name="sent" value="true" />';
|
||||||
$form = $this->form['form'];
|
$form = $this->form['form'];
|
||||||
$formData = $this->formInterpretation($form);
|
$formData = $this->formInterpretation($form);
|
||||||
|
@ -211,45 +237,60 @@ class w3form
|
||||||
echo $item;
|
echo $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
echo '</form>';
|
||||||
echo '</form></div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formField($attribute, $sent): void
|
public function formField($attribute, $sent): void
|
||||||
{
|
{
|
||||||
$style = '';
|
$style = '';
|
||||||
$value = '';
|
$value = '';
|
||||||
$parameter = "name=\"{$attribute['name']}\"";
|
|
||||||
if ($sent && !$this->formFieldCorrect($attribute))
|
|
||||||
$style = "style=\"background-color:{$this->form['colorError']};\"";
|
|
||||||
|
|
||||||
switch ($attribute['type']) {
|
$parameter = empty($attribute['id']) ? 'id="' . $attribute['name'] . '"' : 'id="' . $attribute['id'] . '"';
|
||||||
case 'select':
|
|
||||||
case 'password':
|
$parameter .= ' name="' . $attribute['name'] . '"';
|
||||||
case 'text':
|
|
||||||
if (!empty($attribute['size']))
|
if ($sent && !$this->formFieldCorrect($attribute)) {
|
||||||
$parameter .= " size=\"{$attribute['size']}\"";
|
$style = 'style="background-color: ' . $this->form['colorError'] . ';"';
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
if (!empty($attribute['class'])) {
|
||||||
|
$parameter .= ' class="' . $attribute['class'] . '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($attribute['placeholder'])) {
|
||||||
|
$parameter .= ' placeholder="' . $attribute['placeholder'] . '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($attribute['type']) {
|
switch ($attribute['type']) {
|
||||||
case 'textarea':
|
case 'textarea':
|
||||||
case 'text':
|
case 'text':
|
||||||
if (!empty($attribute['size']))
|
if (!empty($attribute['size'])) {
|
||||||
$parameter .= " size=\"{$attribute['size']}\"";
|
$parameter .= ' size="' . $attribute['size'] . '"';
|
||||||
if (!empty($attribute['value']))
|
}
|
||||||
|
if (!empty($attribute['value'])) {
|
||||||
$value = $attribute['value'];
|
$value = $attribute['value'];
|
||||||
if (!empty($_POST["{$attribute['name']}"]))
|
}
|
||||||
|
if (!empty($_POST["{$attribute['name']}"])) {
|
||||||
$value = $_POST["{$attribute['name']}"];
|
$value = $_POST["{$attribute['name']}"];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'select':
|
||||||
|
case 'password':
|
||||||
|
if (!empty($attribute['size'])) {
|
||||||
|
$parameter .= ' size="' . $attribute['size'] . '"';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($attribute['required']) || isset($attribute['mandantory'])) {
|
||||||
|
$parameter .= ' required';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($attribute['type']) {
|
switch ($attribute['type']) {
|
||||||
case 'captcha':
|
case 'captcha':
|
||||||
if ($this->captchaInstalled) {
|
if ($this->captchaInstalled) {
|
||||||
if ($sent) {
|
if ($sent) {
|
||||||
$captcha = @$_POST['ct_captcha'];
|
$captcha = @$_POST['lets_check'];
|
||||||
$capId = @$_POST['captcha_id'];
|
|
||||||
$securimage = new Securimage();
|
$securimage = new Securimage();
|
||||||
|
|
||||||
if (!$securimage->check($captcha)) {
|
if (!$securimage->check($captcha)) {
|
||||||
|
@ -260,9 +301,10 @@ class w3form
|
||||||
}
|
}
|
||||||
// show captcha HTML using Securimage::getCaptchaHtml()
|
// show captcha HTML using Securimage::getCaptchaHtml()
|
||||||
$options = [];
|
$options = [];
|
||||||
$options['input_name'] = 'ct_captcha'; // change name of input element for form post input_text
|
$options['show_audio_button'] = false;
|
||||||
|
$options['input_name'] = 'lets_check'; // change name of input element for form post input_text
|
||||||
$options['input_text'] = mi18n("Zeichen eingeben");
|
$options['input_text'] = mi18n("Zeichen eingeben");
|
||||||
$options['input_required'] = false;
|
$options['input_required'] = true;
|
||||||
|
|
||||||
if (!empty($_SESSION['ctform']['captcha_error'])) {
|
if (!empty($_SESSION['ctform']['captcha_error'])) {
|
||||||
// error html to show in captcha output
|
// error html to show in captcha output
|
||||||
|
@ -272,13 +314,13 @@ class w3form
|
||||||
echo "<div id='captcha_container_1'>\n";
|
echo "<div id='captcha_container_1'>\n";
|
||||||
echo Securimage::getCaptchaHtml($options);
|
echo Securimage::getCaptchaHtml($options);
|
||||||
echo "\n</div>\n";
|
echo "\n</div>\n";
|
||||||
|
echo '<script src="securimage/securimage.js"></script>';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'text':
|
case 'text':
|
||||||
echo "<input type=\"text\" $parameter value=\"$value\" $style />";
|
case 'email':
|
||||||
break;
|
|
||||||
case 'password':
|
case 'password':
|
||||||
echo "<input type=\"password\" $parameter value=\"$value\" $style />";
|
echo '<input type="'.$attribute['type'].'" '.$parameter.' value="'.$value.'" '.$style.' />';
|
||||||
break;
|
break;
|
||||||
case 'textarea':
|
case 'textarea':
|
||||||
echo "<textarea name=\"{$attribute['name']}\" cols=\"";
|
echo "<textarea name=\"{$attribute['name']}\" cols=\"";
|
||||||
|
@ -289,29 +331,24 @@ class w3form
|
||||||
break;
|
break;
|
||||||
case 'select':
|
case 'select':
|
||||||
echo "<select $parameter $style>";
|
echo "<select $parameter $style>";
|
||||||
for ($i = 0; $i < (is_countable($attribute['option']) ? count($attribute['option']) : 0); $i++) {
|
$itemsCount = is_countable($attribute['option']) ? count($attribute['option']) : 0;
|
||||||
|
for ($i = 0; $i < (is_countable($attribute['option']) ? $itemsCount : 0); $i++) {
|
||||||
if (!empty($attribute['optionvalue'][$i])) {
|
if (!empty($attribute['optionvalue'][$i])) {
|
||||||
if (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $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";
|
echo "<option value=\"{$attribute['optionvalue'][$i]}\" selected=\"selected\">{$attribute['option'][$i]}</option>\n";
|
||||||
} else {
|
} elseif (empty($_POST["{$attribute['name']}"]) && !empty($attribute['optionvalue'][$i]) && $attribute['optionvalue'][$i] == $attribute['value']) {
|
||||||
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";
|
echo "<option value=\"{$attribute['optionvalue'][$i]}\" selected=\"selected\">{$attribute['option'][$i]}</option>\n";
|
||||||
} else {
|
} else {
|
||||||
echo "<option value=\"{$attribute['optionvalue'][$i]}\">{$attribute['option'][$i]}</option>\n";
|
echo "<option value=\"{$attribute['optionvalue'][$i]}\">{$attribute['option'][$i]}</option>\n";
|
||||||
}
|
}
|
||||||
}
|
} elseif (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $attribute['option'][$i]) {
|
||||||
} else {
|
|
||||||
if (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $attribute['option'][$i]) {
|
|
||||||
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
|
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
|
||||||
} else {
|
} elseif (empty($_POST["{$attribute['name']}"]) && $attribute['option'][$i] == $attribute['value']) {
|
||||||
if (empty($_POST["{$attribute['name']}"]) && $attribute['option'][$i] == $attribute['value']) {
|
|
||||||
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
|
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
|
||||||
} else {
|
} else {
|
||||||
echo "<option>{$attribute['option'][$i]}</option>\n";
|
echo "<option>{$attribute['option'][$i]}</option>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
break;
|
break;
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
|
@ -322,13 +359,11 @@ class w3form
|
||||||
} else {
|
} else {
|
||||||
echo "<label $style><input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/></label>";
|
echo "<label $style><input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/></label>";
|
||||||
}
|
}
|
||||||
} else {
|
} elseif (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
|
||||||
if (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
|
|
||||||
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
|
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
|
||||||
} else {
|
} else {
|
||||||
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/>";
|
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/>";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'radio':
|
case 'radio':
|
||||||
if (!empty($_POST["{$attribute['name']}"])) {
|
if (!empty($_POST["{$attribute['name']}"])) {
|
||||||
|
@ -337,13 +372,11 @@ class w3form
|
||||||
} else {
|
} else {
|
||||||
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" />";
|
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" />";
|
||||||
}
|
}
|
||||||
} else {
|
} elseif (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
|
||||||
if (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
|
|
||||||
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
|
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
|
||||||
} else {
|
} else {
|
||||||
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\"/>";
|
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\"/>";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,7 +389,7 @@ class w3form
|
||||||
switch ($field['type']) {
|
switch ($field['type']) {
|
||||||
case 'captcha':
|
case 'captcha':
|
||||||
if ($this->captchaInstalled) {
|
if ($this->captchaInstalled) {
|
||||||
$captcha = @$_POST['ct_captcha'];
|
$captcha = @$_POST['lets_check'];
|
||||||
$capId = @$_POST['captcha_id'];
|
$capId = @$_POST['captcha_id'];
|
||||||
$securimage = new Securimage();
|
$securimage = new Securimage();
|
||||||
if (!$securimage->check($captcha, $capId, true)) {
|
if (!$securimage->check($captcha, $capId, true)) {
|
||||||
|
@ -377,7 +410,13 @@ class w3form
|
||||||
private function success(): void
|
private function success(): void
|
||||||
{
|
{
|
||||||
if ($this->sendEmail()) {
|
if ($this->sendEmail()) {
|
||||||
|
$answer = trim($this->form['answer']);
|
||||||
|
|
||||||
|
if (mb_strlen($answer) > 0) {
|
||||||
echo $this->form['answer'];
|
echo $this->form['answer'];
|
||||||
|
} else {
|
||||||
|
echo '<span style="color:green;">' . mi18n("Form has been successfully send.") . '</span>';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
echo '<span style="color:red;">' . mi18n("Es ist ein Fehler aufgetreten!<br>Bitte versuchen Sie es später noch einmal.") . '</span>';
|
echo '<span style="color:red;">' . mi18n("Es ist ein Fehler aufgetreten!<br>Bitte versuchen Sie es später noch einmal.") . '</span>';
|
||||||
}
|
}
|
||||||
|
@ -389,10 +428,8 @@ class w3form
|
||||||
$tmp_name = rtrim($field['name'], '[0]');
|
$tmp_name = rtrim($field['name'], '[0]');
|
||||||
preg_match('/\[(\d*)\]/', $field['name'], $matches);
|
preg_match('/\[(\d*)\]/', $field['name'], $matches);
|
||||||
$bEmptyPost = false;
|
$bEmptyPost = false;
|
||||||
$bIsPostArray = false;
|
|
||||||
$sPostFieldValue = $_POST[$tmp_name];
|
$sPostFieldValue = $_POST[$tmp_name];
|
||||||
if (is_array($_POST[$tmp_name])) {
|
if (is_array($_POST[$tmp_name])) {
|
||||||
$bIsPostArray == true;
|
|
||||||
$sPostFieldValue = $_POST[$tmp_name][$matches[1]];
|
$sPostFieldValue = $_POST[$tmp_name][$matches[1]];
|
||||||
if (empty($_POST[$tmp_name][$matches[1]])) {
|
if (empty($_POST[$tmp_name][$matches[1]])) {
|
||||||
$bEmptyPost = true;
|
$bEmptyPost = true;
|
||||||
|
@ -465,10 +502,7 @@ class w3form
|
||||||
// längenbereich bei allen typen prüfen
|
// längenbereich bei allen typen prüfen
|
||||||
if (!empty($field['minlength']) && strlen($sPostFieldValue) < $field['minlength'])
|
if (!empty($field['minlength']) && strlen($sPostFieldValue) < $field['minlength'])
|
||||||
return false;
|
return false;
|
||||||
if (!empty($field['maxlength']) && strlen($sPostFieldValue) > $field['maxlength'])
|
return !(!empty($field['maxlength']) && strlen($sPostFieldValue) > $field['maxlength']);
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process(): void
|
public function process(): void
|
||||||
|
@ -484,23 +518,27 @@ class w3form
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($edit) && $edit) {
|
if (cRegistry::isBackendEditMode()) {
|
||||||
echo "<h1>" . mi18n("Formularkonfiguration") . "</h1>";
|
echo "<hr>";
|
||||||
echo "<p>" . mi18n("Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:") . "</p>";
|
echo "<h3>" . mi18n("Formularkonfiguration") . "</h3>";
|
||||||
echo "CMS_HTML[0]";
|
echo "<h4>" . mi18n("Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:") . "</h4>";
|
||||||
echo "<p>" . mi18n("Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich prozessiert worden ist:") . "</p>";
|
echo "CMS_HTML[100]";
|
||||||
echo "CMS_HTML[1]";
|
echo "<h4>" . mi18n("Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich verschickt wurde:") . "</h4>";
|
||||||
|
echo "CMS_HTML[101]";
|
||||||
|
echo "<hr>";
|
||||||
} else {
|
} else {
|
||||||
$form = new w3form($captchaInstalled);
|
$form = new FormGenerator($captchaInstalled, $sess);
|
||||||
$form->addEmailAdress("CMS_VALUE[0]");
|
$form->addEmailAdress("CMS_VALUE[0]");
|
||||||
$form->setEmailSubject("CMS_VALUE[1]");
|
$form->setEmailSubject("CMS_VALUE[1]");
|
||||||
$form->setEmailFrom("CMS_VALUE[2]", "CMS_VALUE[3]");
|
$form->setEmailFrom("CMS_VALUE[2]", "CMS_VALUE[3]");
|
||||||
$form->setBackgroundError("CMS_VALUE[4]");
|
$form->setBackgroundError("CMS_VALUE[4]");
|
||||||
$form->setForm("CMS_HTML[0]");
|
$form->setForm("CMS_HTML[100]");
|
||||||
$form->setAnswer("CMS_HTML[1]");
|
$form->setAnswer("CMS_HTML[101]");
|
||||||
$form->process();
|
$form->process();
|
||||||
}
|
}
|
||||||
?></output>
|
|
||||||
|
?>
|
||||||
|
</output>
|
||||||
</module>
|
</module>
|
||||||
<jsfiles/>
|
<jsfiles/>
|
||||||
<tplfiles/>
|
<tplfiles/>
|
|
@ -1,398 +0,0 @@
|
||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
||||||
<modulepackage><package_guid/>
|
|
||||||
<package_data>a:5:{s:7:"jsfiles";a:0:{}s:8:"tplfiles";a:0:{}s:8:"cssfiles";a:0:{}s:7:"layouts";a:0:{}s:12:"translations";a:0:{}}</package_data>
|
|
||||||
<module><name>KontaktForm_Valid</name>
|
|
||||||
<description><Ihre Modulbeschreibung>
|
|
||||||
|
|
||||||
Autor:
|
|
||||||
Version</description>
|
|
||||||
<type/>
|
|
||||||
<input>?><?php
|
|
||||||
|
|
||||||
/**************************************************
|
|
||||||
* CONTENIDO MODULE - INPUT
|
|
||||||
*
|
|
||||||
* Modulname : w3concepts.form.v1
|
|
||||||
* Author : Andreas Kummer
|
|
||||||
* Copyright : mumprecht & kummer w3concepts
|
|
||||||
* Created : 20-08-2004
|
|
||||||
* Modified : 20-08-2004
|
|
||||||
* Modified : 24-08-2013, Murat Purc, adapted to newer CONTENIDO (4.8) version
|
|
||||||
*************************************************/
|
|
||||||
|
|
||||||
echo "
|
|
||||||
<table cellspacing='0' cellpadding='10' border='0'>
|
|
||||||
<tr>
|
|
||||||
<td>" . mi18n("Zieladresse (alias@mydomain.com):") . "</td>
|
|
||||||
<td><input type='text' name=\"CMS_VAR[0]\" value=\"CMS_VALUE[0]\" size='30' /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>" . mi18n("Betreff:") . "</td>
|
|
||||||
<td><input type='text' name=\"CMS_VAR[1]\" value=\"CMS_VALUE[1]\" size='30' /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>" . mi18n("Antwortadresse (alias@mydomain.com):") . "</td>
|
|
||||||
<td><input type='text' name=\"CMS_VAR[2]\" value=\"CMS_VALUE[2]\" size='30' /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>" . mi18n("Emailname (z.B. Vorname Name):") . "</td>
|
|
||||||
<td><input type='text' name=\"CMS_VAR[3]\" value=\"CMS_VALUE[3]\" size='30' /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>" . mi18n("Hintergrundfarbe bei Fehlern (z.B. red):") . "</td>
|
|
||||||
<td><input type='text' name=\"CMS_VAR[4]\" value=\"CMS_VALUE[4]\" size='30' /></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
";
|
|
||||||
</input>
|
|
||||||
<output><?php
|
|
||||||
|
|
||||||
/**************************************************
|
|
||||||
* CONTENIDO MODULE - OUTPUT
|
|
||||||
*
|
|
||||||
* Modulname : w3concepts.form.v1
|
|
||||||
* Author : Andreas Kummer
|
|
||||||
* Copyright : mumprecht & kummer w3concepts
|
|
||||||
* Created : 20-08-2004
|
|
||||||
* Modified : 20-08-2004
|
|
||||||
* Modified : 24-08-2013, Murat Purc, adapted to newer CONTENIDO (4.8) and PHP (5.3/5.4) versions
|
|
||||||
*************************************************/
|
|
||||||
|
|
||||||
class w3form {
|
|
||||||
|
|
||||||
private $email;
|
|
||||||
private $unraveled = array();
|
|
||||||
private $form;
|
|
||||||
private $formField = array();
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
$this->email = array(
|
|
||||||
'adresses' => '',
|
|
||||||
'from' => array(
|
|
||||||
'name' => '',
|
|
||||||
'email' => ''
|
|
||||||
),
|
|
||||||
'message' => '',
|
|
||||||
'subject' => ''
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->form = array(
|
|
||||||
'form' => '',
|
|
||||||
'answer' => '',
|
|
||||||
'colorError' => ''
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sendEmail() {
|
|
||||||
$this->unravel($this->suppress('sent'));
|
|
||||||
$this->generateEmailMessage();
|
|
||||||
mail(
|
|
||||||
$this->email['adresses'],
|
|
||||||
$this->email['subject'],
|
|
||||||
$this->email['message'],
|
|
||||||
sprintf(
|
|
||||||
"From: %s <%s>\nReply-To: %s\nX-Mailer: PHP/%s",
|
|
||||||
$this->email['from']['name'],
|
|
||||||
$this->email['from']['email'],
|
|
||||||
$this->email['from']['email'],
|
|
||||||
phpversion()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function unravel($toUnravel, $prefix = '') {
|
|
||||||
foreach ($toUnravel as $key => $value) {
|
|
||||||
if (is_array($value)) {
|
|
||||||
$this->unravel($value, $key . ' ');
|
|
||||||
} else {
|
|
||||||
$this->unraveled["{$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->unraveled)
|
|
||||||
foreach ($this->unraveled as $key => $value) {
|
|
||||||
$this->add2Message($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function formInterpretation(&$form) {
|
|
||||||
$fields = explode('###', $form);
|
|
||||||
$field = array();
|
|
||||||
|
|
||||||
for ($i = 1; $i < count($fields); $i = $i + 2) {
|
|
||||||
$attributte = explode(';', trim($fields[$i]));
|
|
||||||
foreach ($attributte as $attribute) {
|
|
||||||
$nameValue = explode(':', trim($attribute));
|
|
||||||
if ($nameValue[0] != 'option' && $nameValue[0] != 'optionvalue') {
|
|
||||||
$field["{$fields[$i]}"]["{$nameValue[0]}"] = $nameValue[1];
|
|
||||||
} else {
|
|
||||||
$field["{$fields[$i]}"]["{$nameValue[0]}"][] = $nameValue[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $field;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function formOutput($sent = false) {
|
|
||||||
echo '<div class="textItem secondItem"><form action="" method="POST" class="form-horizontal">';
|
|
||||||
echo '<input type="hidden" name="sent" value="true" />';
|
|
||||||
$form = $this->form['form'];
|
|
||||||
$formData = $this->formInterpretation($form);
|
|
||||||
$form = explode('###', $form);
|
|
||||||
|
|
||||||
foreach ($form as $item) {
|
|
||||||
if (!empty($formData["{$item}"])) {
|
|
||||||
$this->formField($formData["{$item}"], $sent);
|
|
||||||
} else {
|
|
||||||
echo $item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '</form></div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function formField($attribute, $sent) {
|
|
||||||
$parameter = "name=\"{$attribute['name']}\"";
|
|
||||||
if ($sent && !$this->formFieldCorrect($attribute))
|
|
||||||
$style = "style=\"background-color:{$this->form['colorError']};\"";
|
|
||||||
|
|
||||||
switch ($attribute['type']) {
|
|
||||||
case 'select':
|
|
||||||
case 'password':
|
|
||||||
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 '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':
|
|
||||||
$formId = preg_split('[\[|\]]', $attribute['name']);
|
|
||||||
if ($sent) {
|
|
||||||
if ($_POST["{$formId[0]}"]["{$formId[1]}"] == $attribute['value']) {
|
|
||||||
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 formComplete() {
|
|
||||||
$form = $this->form['form'];
|
|
||||||
$fields = $this->formInterpretation($form);
|
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
if (!$this->formFieldCorrect($field)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function success() {
|
|
||||||
$this->sendEmail();
|
|
||||||
echo $this->form['answer'];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function formFieldCorrect(&$field) {
|
|
||||||
// prüfung, ob pflichtfeld vorhanden
|
|
||||||
if (!empty($field['mandatory']) && $field['mandatory'] == 'true' && empty($_POST["{$field['name']}"]))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// wenn das formularfeld kein pflichtfeld und nicht vorhanden ist, true zurück geben
|
|
||||||
if (empty($_POST["{$field['name']}"]))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// regular expression prüfungen
|
|
||||||
if (!empty($field['valid']) && $field['valid'] == 'simpletext' && !preg_match("/^[öäüéàèâêîça-z-]*$/i", $_POST["{$field['name']}"]))
|
|
||||||
return false;
|
|
||||||
if (!empty($field['valid']) && $field['valid'] == 'text' && !preg_match("/^[ .,;!?()öäüéàèâêîça-z-]*$/i", $_POST["{$field['name']}"]))
|
|
||||||
return false;
|
|
||||||
if (!empty($field['valid']) && $field['valid'] == 'integer' && !preg_match("/^[0-9]*$/", $_POST["{$field['name']}"]))
|
|
||||||
return false;
|
|
||||||
if (!empty($field['valid']) && $field['valid'] == 'float' && !preg_match("/^[0-9]*[.]{0,1}[0-9]*$/", $_POST["{$field['name']}"]))
|
|
||||||
return false;
|
|
||||||
if (!empty($field['valid']) && $field['valid'] == 'date' && !preg_match("/^[0-9]{1,2}.[0-9]{1,2}.[0-9]{2}$/", $_POST["{$field['name']}"]))
|
|
||||||
return false;
|
|
||||||
if (!empty($field['valid']) && $field['valid'] == 'email' && !preg_match("/^[öäüéàèâêîç_a-z0-9-]+(\.[öäüéàèâêîç_a-z0-9-]+)*@[öäüéàèâêîça-z0-9-]+(\.[öäüéàèâêîça-z0-9-]+)*$/i", $_POST["{$field['name']}"]))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// grössenbereich bei integer und float prüfen
|
|
||||||
if (!empty($field['minvalue']) && $_POST["{$field['name']}"] < $field['minvalue'])
|
|
||||||
return false;
|
|
||||||
if (!empty($field['maxvalue']) && $_POST["{$field['name']}"] > $field['maxvalue'])
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// längenbereich bei allen typen prüfen
|
|
||||||
if (!empty($field['minlength']) && strlen($_POST["{$field['name']}"]) < $field['minlength'])
|
|
||||||
return false;
|
|
||||||
if (!empty($field['maxlength']) && strlen($_POST["{$field['name']}"]) > $field['maxlength'])
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function process() {
|
|
||||||
if (!isset($_POST['sent'])) {
|
|
||||||
$this->formOutput();
|
|
||||||
} elseif ($this->formComplete()) {
|
|
||||||
$this->success();
|
|
||||||
} else {
|
|
||||||
$this->formOutput(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($edit) && $edit) {
|
|
||||||
echo "<h1>" . mi18n("Formularkonfiguration") . "</h1>";
|
|
||||||
echo "<p>" . mi18n("Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:") . "</p>";
|
|
||||||
echo "CMS_HTML[0]";
|
|
||||||
echo "<p>" . mi18n("Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich prozessiert worden ist:") . "</p>";
|
|
||||||
echo "CMS_HTML[1]";
|
|
||||||
} else {
|
|
||||||
$form = new w3form();
|
|
||||||
$form->addEmailAdress("CMS_VALUE[0]");
|
|
||||||
$form->setEmailSubject("CMS_VALUE[1]");
|
|
||||||
$form->setEmailFrom("CMS_VALUE[2]", "CMS_VALUE[3]");
|
|
||||||
$form->setBackgroundError("CMS_VALUE[4]");
|
|
||||||
$form->setForm("CMS_HTML[0]");
|
|
||||||
$form->setAnswer("CMS_HTML[1]");
|
|
||||||
$form->process();
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
</output>
|
|
||||||
</module>
|
|
||||||
<jsfiles/>
|
|
||||||
<tplfiles/>
|
|
||||||
<cssfiles/>
|
|
||||||
<layouts/>
|
|
||||||
</modulepackage>
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren