Captcha error if captcha not set in form def Closes #7

Dieser Commit ist enthalten in:
o.pinke 2023-04-26 17:03:26 +02:00
Ursprung 7a0bc2d4f3
Commit a06a6050c4
2 geänderte Dateien mit 104 neuen und 78 gelöschten Zeilen

Datei anzeigen

@ -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]");

Datei anzeigen

@ -57,10 +57,16 @@ $oCfgTable-&gt;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())[&#039;path&#039;][&#039;frontend&#039;] . &#039;securimage&#039; . DIRECTORY_SEPARATOR;
require_once $sFrontEndPath . &#039;securimage.php&#039;;
require_once $sFrontEndPath . &#039;CaptchaObject.php&#039;;
require_once $sFrontEndPath . &#039;StorageAdapter/AdapterInterface.php&#039;;
$captchaInstalled = false;
if (is_readable($sFrontEndPath)) {
require_once $sFrontEndPath . &#039;securimage.php&#039;;
require_once $sFrontEndPath . &#039;CaptchaObject.php&#039;;
require_once $sFrontEndPath . &#039;StorageAdapter/AdapterInterface.php&#039;;
$captchaInstalled = true;
}
class w3form
{
@ -68,10 +74,10 @@ class w3form
private array $email = [&#039;adresses&#039; =&gt; &#039;&#039;, &#039;from&#039; =&gt; [&#039;name&#039; =&gt; &#039;&#039;, &#039;email&#039; =&gt; &#039;&#039;], &#039;message&#039; =&gt; &#039;&#039;, &#039;subject&#039; =&gt; &#039;&#039;];
private array $unraveled = [];
private array $form = [&#039;form&#039; =&gt; &#039;&#039;, &#039;answer&#039; =&gt; &#039;&#039;, &#039;colorError&#039; =&gt; &#039;&#039;];
private array $formField = [];
public function __construct()
public function __construct(private bool $captchaInstalled)
{
}
private function sendEmail(): bool
@ -240,31 +246,33 @@ class w3form
switch ($attribute[&#039;type&#039;]) {
case &#039;captcha&#039;:
if ($sent) {
$captcha = @$_POST[&#039;ct_captcha&#039;];
$capId = @$_POST[&#039;captcha_id&#039;];
$securimage = new Securimage();
if ($this-&gt;captchaInstalled) {
if ($sent) {
$captcha = @$_POST[&#039;ct_captcha&#039;];
$capId = @$_POST[&#039;captcha_id&#039;];
$securimage = new Securimage();
if (!$securimage-&gt;check($captcha)) {
echo &#039;&lt;style&gt;&#039;
. &#039;#captcha_code {background-color: &#039; . $this-&gt;form[&#039;colorError&#039;] . &#039;}&#039;
. &#039;&lt;/style&gt;&#039;;
if (!$securimage-&gt;check($captcha)) {
echo &#039;&lt;style&gt;&#039;
. &#039;#captcha_code {background-color: &#039; . $this-&gt;form[&#039;colorError&#039;] . &#039;}&#039;
. &#039;&lt;/style&gt;&#039;;
}
}
}
// show captcha HTML using Securimage::getCaptchaHtml()
$options = [];
$options[&#039;input_name&#039;] = &#039;ct_captcha&#039;; // change name of input element for form post input_text
$options[&#039;input_text&#039;] = mi18n(&quot;Zeichen eingeben&quot;);
$options[&#039;input_required&#039;] = false;
// show captcha HTML using Securimage::getCaptchaHtml()
$options = [];
$options[&#039;input_name&#039;] = &#039;ct_captcha&#039;; // change name of input element for form post input_text
$options[&#039;input_text&#039;] = mi18n(&quot;Zeichen eingeben&quot;);
$options[&#039;input_required&#039;] = false;
if (!empty($_SESSION[&#039;ctform&#039;][&#039;captcha_error&#039;])) {
// error html to show in captcha output
$options[&#039;error_html&#039;] = $_SESSION[&#039;ctform&#039;][&#039;captcha_error&#039;];
}
if (!empty($_SESSION[&#039;ctform&#039;][&#039;captcha_error&#039;])) {
// error html to show in captcha output
$options[&#039;error_html&#039;] = $_SESSION[&#039;ctform&#039;][&#039;captcha_error&#039;];
}
echo &quot;&lt;div id=&#039;captcha_container_1&#039;&gt;\n&quot;;
echo Securimage::getCaptchaHtml($options);
echo &quot;\n&lt;/div&gt;\n&quot;;
echo &quot;&lt;div id=&#039;captcha_container_1&#039;&gt;\n&quot;;
echo Securimage::getCaptchaHtml($options);
echo &quot;\n&lt;/div&gt;\n&quot;;
}
break;
case &#039;text&#039;:
echo &quot;&lt;input type=\&quot;text\&quot; $parameter value=\&quot;$value\&quot; $style /&gt;&quot;;
@ -345,8 +353,22 @@ class w3form
$form = $this-&gt;form[&#039;form&#039;];
$fields = $this-&gt;formInterpretation($form);
foreach ($fields as $field) {
if (!$this-&gt;formFieldCorrect($field)) {
return false;
switch ($field[&#039;type&#039;]) {
case &#039;captcha&#039;:
if ($this-&gt;captchaInstalled) {
$captcha = @$_POST[&#039;ct_captcha&#039;];
$capId = @$_POST[&#039;captcha_id&#039;];
$securimage = new Securimage();
if (!$securimage-&gt;check($captcha, $capId, true)) {
echo &#039;&lt;div style=&quot;color: red;&quot;&gt;&#039; . mi18n(&quot;Ihr Captcha Code war nicht korrekt. Bitte versuchen Sie es erneut.&quot;) . &#039;&lt;/div&gt;&#039;;
return false;
}
}
break;
default:
if (!$this-&gt;formFieldCorrect($field)) {
return false;
}
}
}
return true;
@ -454,16 +476,7 @@ class w3form
if (!isset($_POST[&#039;sent&#039;])) {
$this-&gt;formOutput();
} elseif ($this-&gt;formComplete()) {
// check captcha
$captcha = @$_POST[&#039;ct_captcha&#039;];
$capId = @$_POST[&#039;captcha_id&#039;];
$securimage = new Securimage();
if (!$securimage-&gt;check($captcha, $capId, true)) {
echo &#039;&lt;div style=&quot;color: red;&quot;&gt;&#039; . mi18n(&quot;Ihr Captcha Code war nicht korrekt. Bitte versuchen Sie es erneut.&quot;) . &#039;&lt;/div&gt;&#039;;
$this-&gt;formOutput(true);
} else {
$this-&gt;success();
}
$this-&gt;success();
} else {
$this-&gt;formOutput(true);
}
@ -478,7 +491,7 @@ if (isset($edit) &amp;&amp; $edit) {
echo &quot;&lt;p&gt;&quot; . mi18n(&quot;Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich prozessiert worden ist:&quot;) . &quot;&lt;/p&gt;&quot;;
echo &quot;CMS_HTML[1]&quot;;
} else {
$form = new w3form();
$form = new w3form($captchaInstalled);
$form-&gt;addEmailAdress(&quot;CMS_VALUE[0]&quot;);
$form-&gt;setEmailSubject(&quot;CMS_VALUE[1]&quot;);
$form-&gt;setEmailFrom(&quot;CMS_VALUE[2]&quot;, &quot;CMS_VALUE[3]&quot;);