Forum prefix doesn't work Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.
3 posters

    Forum prefix doesn't work

    avatar
    Guest
    Guest


    Solved Forum prefix doesn't work

    Post by Guest 15/2/2023, 07:30

    Forum URL: https://academy.forumotion.me/
    Version: ModernBB

    I shared on my forum an article about sexual harrasmant and what causes such things during war (psychology point of view). Here is the link to that topic: https://academy.forumotion.me/t112-undefined-why-is-sexual-violence-so-common-in-war

    But, when I select prefix to be article, and go to post topic, they ask me to confirm by captcha and when I do, it says undefined prefix. Why I get captcha message? Is it because of the article content?


    Last edited by Academic on 16/2/2023, 13:26; edited 1 time in total
    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15391
    Reputation : 1709
    Language : English,Greek
    Location : Greece

    Solved Re: Forum prefix doesn't work

    Post by skouliki 15/2/2023, 08:21

    Hello

    Which code/ tutorial did you used?

    avatar
    Guest
    Guest


    Solved Re: Forum prefix doesn't work

    Post by Guest 15/2/2023, 08:57

    This one:

    Code:
    var prefixes = ["News", "Article", "Tutorial", "Help"]; //your prefixes
    var _pm = false; //true: allowed prefixes in pm
    var chk = false;
    function toMenu(a) {
      var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
      for (i in a)
      htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
      htmlpre += '</select>';
      return htmlpre;
    }
     
    function checkpre(ar, input) {
      for (i in ar) {
          var p = new RegExp("\\" + ar[i], "g");
          var title = input.substr(0, input.indexOf(']'));
          if (p.test(title)) return ar[i];
      }
      return "";
    }
    $(function () {
      if (_pm) chk = /\privmsg/.test(location.href);
      if (/\/post/.test(location.href) || chk) {
          $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
          var mw = $("#prefix").width() + 5;
          $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
          var t = $("[name='subject']").val();
          var cur = checkpre(prefixes, t);
          if (cur != "") {
            $("[value=" + cur + "]").attr("selected", "selected");
            $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
          }
          $("input[name='post']").click(function () {
            var sub = $("input[name='subject']").val().trim();
            if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
          })
      }
    });
     
    $(function () {
      $("a[href^='/t'], a[href^='http://" + location.host + "/t']").html(function () {
          var a = $(this).text();
          if(/^\[([^\[\]]+)\]/.test(a)) return a.replace(/^\[[^\[\]]+\]/, function (a) {
            return '<span class="prefix ' + a + '">' + a.slice(1,-1) + "</span>"
          })
      });
    });

    The problem is not in the code. Issue is when I click to post the topic, I get redirected to solve captcha and during that time, things get messed up.
    avatar
    Guest
    Guest


    Solved Re: Forum prefix doesn't work

    Post by Guest 16/2/2023, 09:39

    Bump.
    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15391
    Reputation : 1709
    Language : English,Greek
    Location : Greece

    Solved Re: Forum prefix doesn't work

    Post by skouliki 16/2/2023, 11:54

    did you check if any of your other javascript is causing a conflict ?

    avatar
    Guest
    Guest


    Solved Re: Forum prefix doesn't work

    Post by Guest 16/2/2023, 12:49

    This is not related to other JS. This is mainly related to me getting captcha verification. I don't understand why am I getting it in the first place. Only for that topic. Is it considered bad in your forumotion systems or?

    Forum prefix doesn't work Screen57
    chattigre
    chattigre
    Forumember


    Male Posts : 56
    Reputation : 15
    Language : French (10/10), English (5/10)
    Location : French support forum

    Solved Re: Forum prefix doesn't work

    Post by chattigre 16/2/2023, 12:55

    Hello,

    You may be faced to a Captcha when you attempt to post or edit a message which contains a certain word which has been blacklisted / put on a security list because it is sometimes present in spam messages, unsolicited messages or posts made by bots or spammers to pollute forums.

    It is a security check therefore we don't have any control over that.

    So, let's try to correct your javascript to make it working even if you have to pass the Captcha step.

    The issue looks to be with this condition :
    Code:
            if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
    If the input#prefix is present on the post page but is empty, the .val() method returns an empty string.
    But if this input is simply absent on the page, it returns undefined, and undefined != "", so the condition is executed and the prefix is turned in "undefined".

    To fix it, replace this line with the following :
    Code:
            if (sub != "" && $("#prefix").val()) $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)

    Let me know if it works for you,
    Regards.

    TonnyKamper likes this post

    avatar
    Guest
    Guest


    Solved Re: Forum prefix doesn't work

    Post by Guest 16/2/2023, 13:26

    chattigre wrote:Hello,

    You may be faced to a Captcha when you attempt to post or edit a message which contains a certain word which has been blacklisted / put on a security list because it is sometimes present in spam messages, unsolicited messages or posts made by bots or spammers to pollute forums.

    It is a security check therefore we don't have any control over that.

    So, let's try to correct your javascript to make it working even if you have to pass the Captcha step.

    The issue looks to be with this condition :
    Code:
            if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
    If the input#prefix is present on the post page but is empty, the .val() method returns an empty string.
    But if this input is simply absent on the page, it returns undefined, and undefined != "", so the condition is executed and the prefix is turned in "undefined".

    To fix it, replace this line with the following :
    Code:
            if (sub != "" && $("#prefix").val()) $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)

    Let me know if it works for you,
    Regards.

    Okay, now undefined is gone, but it seems I can't put any prefix due to words prohibited by Forumotion team. Too bad. It's a psychological point of view, academic. Let's say it's solved.
    chattigre
    chattigre
    Forumember


    Male Posts : 56
    Reputation : 15
    Language : French (10/10), English (5/10)
    Location : French support forum

    Solved Re: Forum prefix doesn't work

    Post by chattigre 16/2/2023, 13:29

    Hello again,

    No, let's try to fix it, normally it will be easy, I just did'nt think about it Smile
    Just let me a few hours to do it because now I have to go, but I will come back to you with a fix as soon as possible this evening or tomorrow !
    (Think to remove Solved icon if you want me to do so, otherwise your topic may be archived)
    Regards
    chattigre
    chattigre
    Forumember


    Male Posts : 56
    Reputation : 15
    Language : French (10/10), English (5/10)
    Location : French support forum

    Solved Re: Forum prefix doesn't work

    Post by chattigre 16/2/2023, 14:14

    Hello again,

    Assuming prefix is editable only if "subject" field is an editable text input and not if it is an hidden input, try to replace :
    Code:
      if (/\/post/.test(location.href) || chk) {

    by
    Code:
      if (($('input[name="subject"][type="text"]').length) && (/\/post/.test(location.href) || chk)) {

    So if the subject field is hidden and just present as an hidden fallback / saved field, the JS won't be executed making the prefix consistent.

    I hope this will completely solve your issue this time, otherwise please feel free to advise me of any other unexpected behavior.
    Regards
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3524
    Language : English
    Location : United States

    Solved Re: Forum prefix doesn't work

    Post by SLGray 16/2/2023, 15:16

    Is this solved now?



    Forum prefix doesn't work Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.
    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15391
    Reputation : 1709
    Language : English,Greek
    Location : Greece

    Solved Re: Forum prefix doesn't work

    Post by skouliki 17/2/2023, 00:46

    marked as solved

    Problem solved & topic archived.
    Please read our forum rules: ESF General Rules