Sterc / Formalicious

Other
6 stars 11 forks source link

SPAM Hook: no email and XML errors in log (Could not connect to provider) #13

Closed jenswittmann closed 3 years ago

jenswittmann commented 3 years ago

Hello, i get the following Errors in the MODX log:

[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 240) PHP warning: simplexml_load_string(): Entity: line 3: parser error : Opening and ending tag mismatch: error line 2 and response
[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 240) PHP warning: simplexml_load_string(): </response>
[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 240) PHP warning: simplexml_load_string():            ^
[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 240) PHP warning: simplexml_load_string(): Entity: line 3: parser error : Premature end of data in tag error line 2
[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 240) PHP warning: simplexml_load_string(): </response>
[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 240) PHP warning: simplexml_load_string():            ^
[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 240) PHP warning: simplexml_load_string(): Entity: line 3: parser error : Premature end of data in tag response line 1
[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 240) PHP warning: simplexml_load_string(): </response>
[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 240) PHP warning: simplexml_load_string():            ^
[2021-06-07 14:09:50] (ERROR @ core/model/modx/rest/modrestclient.class.php : 245) Could not connect to provider at: https://api.stopforumspam.com/

First, there is a fix for the FormIt Hook here: https://github.com/Sterc/FormIt/issues/241#issuecomment-855866528

But with Formalicious the SPAM Hook is looking for POST Variable email, but all Formalicious Field are name like field_{N}. So a quickfix is the following:

  1. Get the IDs for all Email Fields you use inside your Formalicious form. For its only one Email Fields with ID 1003. So the POST Variable name is field_1003.
  2. Under the tab "Advances Settings" add a parameter "spamEmailFields" (Docs) width the value "field_1003": image

Now the SPAM Hook knows the right field, send it to stopforumspam.com and get a proper result.

Todo

We should set the parameter spamEmailFields by default. We can get all fields from type "email" and fill the parameter. A solution could be this:

https://github.com/Sterc/Formalicious/blob/2be92e4b15cf8570de1359f1064915de69274344/core/components/formalicious/model/formalicious/snippets/formalicioussnippetrenderform.class.php#L47

// insert on line 324
// set fieldname for spam hook
$emailFieldNames = [];
foreach ((array) $form->getSteps() as $step) {
    foreach ((array) $step->getFields() as $field) {
        if ($field->get('type') == 6) {
            // is there a better check?
            $emailFieldNames[] = 'field_' . $field->get('id');
        }
    }
}
if (count($emailFieldNames) > 0) {
    $parameters['spamEmailFields'] = implode(
        ',',
        $emailFieldNames
    );
}
ilyautkin commented 3 years ago

Fixed in 4.2.7