diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e5a6d4e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +.gitattributes export-ignore +.gitignore export-ignore +.project export-ignore +/nbproject export-ignore +phpdoc.dist.xml export-ignore diff --git a/.gitignore b/.gitignore index 0bd8605..130c22a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,4 @@ dist/ nbdist/ .nb-gradle/ -/php/cl_contactform_output_Dodger.php -/php/cl_contactform_input_Dodger.php +/.dev/ diff --git a/README.md b/README.md index 8eee38d..700a39d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ -# module-cl-contactform +# Module CL Contact Form -contactform module based on w3concepts.form.v1 \ No newline at end of file +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. diff --git a/cl_module.xml b/cl_module.xml new file mode 100644 index 0000000..3ab3b1f --- /dev/null +++ b/cl_module.xml @@ -0,0 +1,31 @@ + + + + CL Contact Form + cl_contact_form + + Default contact formular for CMS ConLite + Ortwin Pinke + Ortwin Pinke php-backoffice.de + + info@php-backoffice.de + https://php-backoffice.de + 1.0.0 + + + + + + \ No newline at end of file diff --git a/php/cl_contact_form_input.php b/php/cl_contact_form_input.php new file mode 100644 index 0000000..13ddcb6 --- /dev/null +++ b/php/cl_contact_form_input.php @@ -0,0 +1,60 @@ +?> + * + * 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) + */ + +cInclude('frontend', 'includes/class.input.helper.php'); +$uiConfigTable = new UI_Config_Table(); + +$htmlField = new cHTMLSelectElement("CMS_VAR[10]", 200); +$htmlField->autoFill([ + 'null' => mi18n("Bitte wählen"), + '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(); + +$htmlField = new cHTMLTextbox("CMS_VAR[0]", "CMS_VALUE[0]"); +$htmlField->setWidth(30); +$uiConfigTable->setRowCell(0, mi18n("Zieladresse (alias@mydomain.com):")); +$uiConfigTable->setRowCell(1, $htmlField->render()); +$uiConfigTable->nextRow(); + +$htmlField = new cHTMLTextbox("CMS_VAR[1]", "CMS_VALUE[1]"); +$htmlField->setWidth(30); +$uiConfigTable->setRowCell(0, mi18n("Betreff:")); +$uiConfigTable->setRowCell(1, $htmlField->render()); +$uiConfigTable->nextRow(); + +$htmlField = new cHTMLTextbox("CMS_VAR[2]", "CMS_VALUE[2]"); +$htmlField->setWidth(30); +$uiConfigTable->setRowCell(0, mi18n("Antwortadresse (alias@mydomain.com):")); +$uiConfigTable->setRowCell(1, $htmlField->render()); +$uiConfigTable->nextRow(); + +$htmlField = new cHTMLTextbox("CMS_VAR[3]", "CMS_VALUE[3]"); +$htmlField->setWidth(30); +$uiConfigTable->setRowCell(0, mi18n("Emailname (z.B. Vorname Name):")); +$uiConfigTable->setRowCell(1, $htmlField->render()); +$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); + +?> * * 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) */ -use PHPMailer\PHPMailer\PHPMailer; - $sFrontEndPath = cRegistry::getClientConfig(cRegistry::getClientId())['path']['frontend'] . 'securimage' . DIRECTORY_SEPARATOR; $captchaInstalled = false; if (is_readable($sFrontEndPath)) { @@ -19,14 +20,15 @@ if (is_readable($sFrontEndPath)) { $captchaInstalled = true; } -class w3form +class FormGenerator { + public $emailAdresses; private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => '']; private array $unraveled = []; private array $form = ['form' => '', 'answer' => '', 'colorError' => '']; - public function __construct(private bool $captchaInstalled) + public function __construct(private bool $captchaInstalled, private cSession $cSession) { } @@ -36,18 +38,22 @@ class w3form $this->unravel($this->suppress('sent')); $this->generateEmailMessage(); - $oMailer = new PHPMailer(); - $oMailer->CharSet = "UTF-8"; - $oMailer->AddAddress($this->email['adresses']); - $oMailer->From = $this->email['from']['email']; - $oMailer->FromName = $this->email['from']['name']; - $oMailer->Subject = $this->email['subject']; - $oMailer->Body = $this->email['message']; + $phpMailer = new \PHPMailer\PHPMailer\PHPMailer(true); + $phpMailer->isMail(); + $phpMailer->isHTML(false); + $phpMailer->CharSet = "UTF-8"; + $phpMailer->AddAddress($this->email['adresses']); + $phpMailer->setFrom($this->email['from']['email'], $this->email['from']['name']); + $phpMailer->Subject = $this->email['subject']; + $phpMailer->Body = $this->email['message']; - if ($oMailer->send()) { - return true; + try { + if ($phpMailer->send()) { + return true; + } + } catch (\PHPMailer\PHPMailer\Exception $e) { + echo $e->errorMessage(); } - return false; } @@ -64,7 +70,7 @@ class w3form 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"; } else { $this->email['message'] .= $key; @@ -75,18 +81,16 @@ class w3form private function generateEmailMessage(): void { - if ($this->unraveled) - foreach ($this->unraveled as $key => $value) { - $this->add2Message($key, $value); - } + foreach ($this->unraveled as $key => $value) { + $this->add2Message($key, $value); + } } - private function suppress(): array + private function suppress(...$suppress): array { $fields = []; - $suppress = func_get_args(); foreach ($_POST as $key => $value) { - if (array_search($key, $suppress) === false) + if (!in_array($key, $suppress)) $fields[$key] = $value; } return $fields; @@ -131,8 +135,9 @@ class w3form { $fields = explode('###', $form); $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])); foreach ($attribute as $attribute) { $nameValue = explode(':', trim($attribute)); @@ -149,7 +154,8 @@ class w3form public function formOutput($sent = false): void { - echo '
'; + $form_action = $this->cSession->url('front_content.php?idcat=' . cRegistry::getCategoryId() . '&idart=' . cRegistry::getArticleId()); + echo ''; echo ''; $form = $this->form['form']; $formData = $this->formInterpretation($form); @@ -162,45 +168,60 @@ class w3form echo $item; } } - - echo '
'; + echo ''; } public function formField($attribute, $sent): void { $style = ''; $value = ''; - $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; + $parameter = empty($attribute['id']) ? 'id="' . $attribute['name'] . '"' : 'id="' . $attribute['id'] . '"'; + + $parameter .= ' name="' . $attribute['name'] . '"'; + + if ($sent && !$this->formFieldCorrect($attribute)) { + $style = 'style="background-color: ' . $this->form['colorError'] . ';"'; + } + + if (!empty($attribute['class'])) { + $parameter .= ' class="' . $attribute['class'] . '"'; + } + + if (!empty($attribute['placeholder'])) { + $parameter .= ' placeholder="' . $attribute['placeholder'] . '"'; } switch ($attribute['type']) { case 'textarea': case 'text': - if (!empty($attribute['size'])) - $parameter .= " size=\"{$attribute['size']}\""; - if (!empty($attribute['value'])) + if (!empty($attribute['size'])) { + $parameter .= ' size="' . $attribute['size'] . '"'; + } + if (!empty($attribute['value'])) { $value = $attribute['value']; - if (!empty($_POST["{$attribute['name']}"])) + } + if (!empty($_POST["{$attribute['name']}"])) { $value = $_POST["{$attribute['name']}"]; + } 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']) { case 'captcha': if ($this->captchaInstalled) { if ($sent) { - $captcha = @$_POST['ct_captcha']; - $capId = @$_POST['captcha_id']; + $captcha = @$_POST['lets_check']; $securimage = new Securimage(); if (!$securimage->check($captcha)) { @@ -211,9 +232,10 @@ class w3form } // show captcha HTML using Securimage::getCaptchaHtml() $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_required'] = false; + $options['input_required'] = true; if (!empty($_SESSION['ctform']['captcha_error'])) { // error html to show in captcha output @@ -223,13 +245,13 @@ class w3form echo "
\n"; echo Securimage::getCaptchaHtml($options); echo "\n
\n"; + echo ''; } break; case 'text': - echo ""; - break; + case 'email': case 'password': - echo ""; + echo ''; break; case 'textarea': echo "