External form submissions fail to redirect on post

Anti-spam plugin for WordPress
User avatar
ben-morin
Posts: 1
Joined: 19 May 2017, 20:25
Location: New Mexico
Has thanked: 1 time
Been thanked: 0
Contact:

External form submissions fail to redirect on post

Unread post by ben-morin » 19 May 2017, 20:31

External form redirects will fail if there isn't a form element with name='submit' and the javascript stops executing when trying to access the first element in the empty array. The fix is to check if getElementsByName() returned any objects:

Revision: 1659892

Code: Select all

diff --git a/inc/cleantalk-public.php b/inc/cleantalk-public.php
index 3f37039..c120394 100644
--- a/inc/cleantalk-public.php
+++ b/inc/cleantalk-public.php
@@ -51,6 +51,7 @@ function ct_init() {
        print "<script>
                        if(document.forms[0].submit != 'undefined'){
                                var objects = document.getElementsByName('submit');
+                if(objects.length > 0)
                                document.forms[0].removeChild(objects[0]);
                        }
                        document.forms[0].submit();

User avatar
SergeM
Posts: 116
Joined: 27 May 2016, 08:05
Has thanked: 11 times
Been thanked: 8 times
Contact:

Re: External form submissions fail to redirect on post

Unread post by SergeM » 21 May 2017, 05:53

Hello.

Thank you for your request and for helping us to make the CleanTalk plugin better!

We will revise the code and apply changes if necessary.

We will inform you when we finish.

Your CleanTalk Control Panel: [ https://cleantalk.org/my/ ].

Best regards.
———————
Technical Support
https://CleanTalk.org — Anti-Spam Modules for all CMS

User avatar
Roman
Posts: 103
Joined: 13 Jan 2016, 08:31
Has thanked: 0
Been thanked: 6 times

Re: External form submissions fail to redirect on post

Unread post by Roman » 22 May 2017, 05:33

Hello,

Thank you for the feedback!

We have added the suggested code. This fix will be in a new release.
If you want to get a bonus you may create a support ticket here: https://cleantalk.org/my/support/open and attach the link to this page.

Contact us if you have other questions or suggestions.
These users thanked the author Roman for the post:
ben-morin (25 May 2017, 17:43)
Rating: 50%
Roman Safronov
Technical Support

Post Reply