Captcha error if captcha not set in form def Closes #7
Dieser Commit ist enthalten in:
Ursprung
7a0bc2d4f3
Commit
a06a6050c4
2 geänderte Dateien mit 104 neuen und 78 gelöschten Zeilen
|
@ -8,10 +8,16 @@
|
|||
* 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;
|
||||
require_once $sFrontEndPath . 'securimage.php';
|
||||
require_once $sFrontEndPath . 'CaptchaObject.php';
|
||||
require_once $sFrontEndPath . 'StorageAdapter/AdapterInterface.php';
|
||||
$captchaInstalled = false;
|
||||
if (is_readable($sFrontEndPath)) {
|
||||
require_once $sFrontEndPath . 'securimage.php';
|
||||
require_once $sFrontEndPath . 'CaptchaObject.php';
|
||||
require_once $sFrontEndPath . 'StorageAdapter/AdapterInterface.php';
|
||||
$captchaInstalled = true;
|
||||
}
|
||||
|
||||
class w3form
|
||||
{
|
||||
|
@ -19,10 +25,10 @@ class w3form
|
|||
private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => ''];
|
||||
private array $unraveled = [];
|
||||
private array $form = ['form' => '', 'answer' => '', 'colorError' => ''];
|
||||
private array $formField = [];
|
||||
|
||||
public function __construct()
|
||||
public function __construct(private bool $captchaInstalled)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function sendEmail(): bool
|
||||
|
@ -191,31 +197,33 @@ class w3form
|
|||
|
||||
switch ($attribute['type']) {
|
||||
case 'captcha':
|
||||
if ($sent) {
|
||||
$captcha = @$_POST['ct_captcha'];
|
||||
$capId = @$_POST['captcha_id'];
|
||||
$securimage = new Securimage();
|
||||
if ($this->captchaInstalled) {
|
||||
if ($sent) {
|
||||
$captcha = @$_POST['ct_captcha'];
|
||||
$capId = @$_POST['captcha_id'];
|
||||
$securimage = new Securimage();
|
||||
|
||||
if (!$securimage->check($captcha)) {
|
||||
echo '<style>'
|
||||
. '#captcha_code {background-color: ' . $this->form['colorError'] . '}'
|
||||
. '</style>';
|
||||
if (!$securimage->check($captcha)) {
|
||||
echo '<style>'
|
||||
. '#captcha_code {background-color: ' . $this->form['colorError'] . '}'
|
||||
. '</style>';
|
||||
}
|
||||
}
|
||||
}
|
||||
// show captcha HTML using Securimage::getCaptchaHtml()
|
||||
$options = [];
|
||||
$options['input_name'] = 'ct_captcha'; // change name of input element for form post input_text
|
||||
$options['input_text'] = mi18n("Zeichen eingeben");
|
||||
$options['input_required'] = false;
|
||||
// show captcha HTML using Securimage::getCaptchaHtml()
|
||||
$options = [];
|
||||
$options['input_name'] = 'ct_captcha'; // change name of input element for form post input_text
|
||||
$options['input_text'] = mi18n("Zeichen eingeben");
|
||||
$options['input_required'] = false;
|
||||
|
||||
if (!empty($_SESSION['ctform']['captcha_error'])) {
|
||||
// error html to show in captcha output
|
||||
$options['error_html'] = $_SESSION['ctform']['captcha_error'];
|
||||
}
|
||||
if (!empty($_SESSION['ctform']['captcha_error'])) {
|
||||
// error html to show in captcha output
|
||||
$options['error_html'] = $_SESSION['ctform']['captcha_error'];
|
||||
}
|
||||
|
||||
echo "<div id='captcha_container_1'>\n";
|
||||
echo Securimage::getCaptchaHtml($options);
|
||||
echo "\n</div>\n";
|
||||
echo "<div id='captcha_container_1'>\n";
|
||||
echo Securimage::getCaptchaHtml($options);
|
||||
echo "\n</div>\n";
|
||||
}
|
||||
break;
|
||||
case 'text':
|
||||
echo "<input type=\"text\" $parameter value=\"$value\" $style />";
|
||||
|
@ -296,8 +304,22 @@ class w3form
|
|||
$form = $this->form['form'];
|
||||
$fields = $this->formInterpretation($form);
|
||||
foreach ($fields as $field) {
|
||||
if (!$this->formFieldCorrect($field)) {
|
||||
return false;
|
||||
switch ($field['type']) {
|
||||
case 'captcha':
|
||||
if ($this->captchaInstalled) {
|
||||
$captcha = @$_POST['ct_captcha'];
|
||||
$capId = @$_POST['captcha_id'];
|
||||
$securimage = new Securimage();
|
||||
if (!$securimage->check($captcha, $capId, true)) {
|
||||
echo '<div style="color: red;">' . mi18n("Ihr Captcha Code war nicht korrekt. Bitte versuchen Sie es erneut.") . '</div>';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!$this->formFieldCorrect($field)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -405,16 +427,7 @@ class w3form
|
|||
if (!isset($_POST['sent'])) {
|
||||
$this->formOutput();
|
||||
} elseif ($this->formComplete()) {
|
||||
// check captcha
|
||||
$captcha = @$_POST['ct_captcha'];
|
||||
$capId = @$_POST['captcha_id'];
|
||||
$securimage = new Securimage();
|
||||
if (!$securimage->check($captcha, $capId, true)) {
|
||||
echo '<div style="color: red;">' . mi18n("Ihr Captcha Code war nicht korrekt. Bitte versuchen Sie es erneut.") . '</div>';
|
||||
$this->formOutput(true);
|
||||
} else {
|
||||
$this->success();
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
$this->formOutput(true);
|
||||
}
|
||||
|
@ -429,7 +442,7 @@ if (isset($edit) && $edit) {
|
|||
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 = new w3form($captchaInstalled);
|
||||
$form->addEmailAdress("CMS_VALUE[0]");
|
||||
$form->setEmailSubject("CMS_VALUE[1]");
|
||||
$form->setEmailFrom("CMS_VALUE[2]", "CMS_VALUE[3]");
|
||||
|
|
|
@ -57,10 +57,16 @@ $oCfgTable->render(true);
|
|||
* 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;
|
||||
require_once $sFrontEndPath . 'securimage.php';
|
||||
require_once $sFrontEndPath . 'CaptchaObject.php';
|
||||
require_once $sFrontEndPath . 'StorageAdapter/AdapterInterface.php';
|
||||
$captchaInstalled = false;
|
||||
if (is_readable($sFrontEndPath)) {
|
||||
require_once $sFrontEndPath . 'securimage.php';
|
||||
require_once $sFrontEndPath . 'CaptchaObject.php';
|
||||
require_once $sFrontEndPath . 'StorageAdapter/AdapterInterface.php';
|
||||
$captchaInstalled = true;
|
||||
}
|
||||
|
||||
class w3form
|
||||
{
|
||||
|
@ -68,10 +74,10 @@ class w3form
|
|||
private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => ''];
|
||||
private array $unraveled = [];
|
||||
private array $form = ['form' => '', 'answer' => '', 'colorError' => ''];
|
||||
private array $formField = [];
|
||||
|
||||
public function __construct()
|
||||
public function __construct(private bool $captchaInstalled)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function sendEmail(): bool
|
||||
|
@ -240,31 +246,33 @@ class w3form
|
|||
|
||||
switch ($attribute['type']) {
|
||||
case 'captcha':
|
||||
if ($sent) {
|
||||
$captcha = @$_POST['ct_captcha'];
|
||||
$capId = @$_POST['captcha_id'];
|
||||
$securimage = new Securimage();
|
||||
if ($this->captchaInstalled) {
|
||||
if ($sent) {
|
||||
$captcha = @$_POST['ct_captcha'];
|
||||
$capId = @$_POST['captcha_id'];
|
||||
$securimage = new Securimage();
|
||||
|
||||
if (!$securimage->check($captcha)) {
|
||||
echo '<style>'
|
||||
. '#captcha_code {background-color: ' . $this->form['colorError'] . '}'
|
||||
. '</style>';
|
||||
if (!$securimage->check($captcha)) {
|
||||
echo '<style>'
|
||||
. '#captcha_code {background-color: ' . $this->form['colorError'] . '}'
|
||||
. '</style>';
|
||||
}
|
||||
}
|
||||
}
|
||||
// show captcha HTML using Securimage::getCaptchaHtml()
|
||||
$options = [];
|
||||
$options['input_name'] = 'ct_captcha'; // change name of input element for form post input_text
|
||||
$options['input_text'] = mi18n("Zeichen eingeben");
|
||||
$options['input_required'] = false;
|
||||
// show captcha HTML using Securimage::getCaptchaHtml()
|
||||
$options = [];
|
||||
$options['input_name'] = 'ct_captcha'; // change name of input element for form post input_text
|
||||
$options['input_text'] = mi18n("Zeichen eingeben");
|
||||
$options['input_required'] = false;
|
||||
|
||||
if (!empty($_SESSION['ctform']['captcha_error'])) {
|
||||
// error html to show in captcha output
|
||||
$options['error_html'] = $_SESSION['ctform']['captcha_error'];
|
||||
}
|
||||
if (!empty($_SESSION['ctform']['captcha_error'])) {
|
||||
// error html to show in captcha output
|
||||
$options['error_html'] = $_SESSION['ctform']['captcha_error'];
|
||||
}
|
||||
|
||||
echo "<div id='captcha_container_1'>\n";
|
||||
echo Securimage::getCaptchaHtml($options);
|
||||
echo "\n</div>\n";
|
||||
echo "<div id='captcha_container_1'>\n";
|
||||
echo Securimage::getCaptchaHtml($options);
|
||||
echo "\n</div>\n";
|
||||
}
|
||||
break;
|
||||
case 'text':
|
||||
echo "<input type=\"text\" $parameter value=\"$value\" $style />";
|
||||
|
@ -345,8 +353,22 @@ class w3form
|
|||
$form = $this->form['form'];
|
||||
$fields = $this->formInterpretation($form);
|
||||
foreach ($fields as $field) {
|
||||
if (!$this->formFieldCorrect($field)) {
|
||||
return false;
|
||||
switch ($field['type']) {
|
||||
case 'captcha':
|
||||
if ($this->captchaInstalled) {
|
||||
$captcha = @$_POST['ct_captcha'];
|
||||
$capId = @$_POST['captcha_id'];
|
||||
$securimage = new Securimage();
|
||||
if (!$securimage->check($captcha, $capId, true)) {
|
||||
echo '<div style="color: red;">' . mi18n("Ihr Captcha Code war nicht korrekt. Bitte versuchen Sie es erneut.") . '</div>';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!$this->formFieldCorrect($field)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -454,16 +476,7 @@ class w3form
|
|||
if (!isset($_POST['sent'])) {
|
||||
$this->formOutput();
|
||||
} elseif ($this->formComplete()) {
|
||||
// check captcha
|
||||
$captcha = @$_POST['ct_captcha'];
|
||||
$capId = @$_POST['captcha_id'];
|
||||
$securimage = new Securimage();
|
||||
if (!$securimage->check($captcha, $capId, true)) {
|
||||
echo '<div style="color: red;">' . mi18n("Ihr Captcha Code war nicht korrekt. Bitte versuchen Sie es erneut.") . '</div>';
|
||||
$this->formOutput(true);
|
||||
} else {
|
||||
$this->success();
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
$this->formOutput(true);
|
||||
}
|
||||
|
@ -478,7 +491,7 @@ if (isset($edit) && $edit) {
|
|||
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 = new w3form($captchaInstalled);
|
||||
$form->addEmailAdress("CMS_VALUE[0]");
|
||||
$form->setEmailSubject("CMS_VALUE[1]");
|
||||
$form->setEmailFrom("CMS_VALUE[2]", "CMS_VALUE[3]");
|
||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren