How can I add an automatic poll like here on the support forum? 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.
2 posters

    How can I add an automatic poll like here on the support forum?

    avatar
    Guest
    Guest


    Solved How can I add an automatic poll like here on the support forum?

    Post by Guest August 31st 2015, 3:00 pm

    Hi, I'm having trouble adding an automatic poll to my forum. I'd like the auto poll to be activated for the suggestions



    Forum Version: PHPBB3

    Forum URL: http://theoriginals.4umotion.com/


    Last edited by Ghost on October 4th 2015, 5:07 pm; edited 2 times in total
    Ace 1
    Ace 1
    Helper
    Helper


    Male Posts : 843
    Reputation : 64
    Language : English - French?
    Location : Druid Hill Park

    Solved Re: How can I add an automatic poll like here on the support forum?

    Post by Ace 1 September 1st 2015, 3:06 am

    You want it so the entire forum is polls? Or just regular topics (excluding sticky's, etc.)
    avatar
    Guest
    Guest


    Solved Re: How can I add an automatic poll like here on the support forum?

    Post by Guest September 1st 2015, 3:21 am

    Ace 1 wrote:You want it so the entire forum is polls? Or just regular topics (excluding sticky's, etc.)
    regular topics.(excluding sticky's etc.)
    avatar
    Guest
    Guest


    Solved Re: How can I add an automatic poll like here on the support forum?

    Post by Guest October 4th 2015, 3:41 pm

    Bump
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: How can I add an automatic poll like here on the support forum?

    Post by Ange Tuteur October 4th 2015, 4:16 pm

    Hi @Ghost,

    You can add this by going to Modules > JavaScript codes management > and create a new script

    Placement : In all the pages
    Code:
    window.location.pathname == '/post' && $(function () {
      var lang = {
        info : 'The poll will be added automatically.',
        poll_question : 'Do you agree or disagree ?',
        poll_answers : 'Agree\nDisagree'
      };

      if (document.post && document.post.mode.value == 'newtopic' && document.post.f.value == 14) {
        $(document.post.poll_title).closest('fieldset').html('<strong>' + lang.info + '</strong><input type="hidden" name="poll_title" value="' + lang.poll_question + '" /><input type="hidden" name="poll_option_text" value="' + lang.poll_answers + '"><input type="hidden" name="poll_length" value="30" /><input type="hidden" name="poll_cancel_vote" value="1" />');
      }
    });

    The 14 in document.post.f.value == 14 is the id of the forum this will be applied to.

    At the top of the script you can adjust the language settings and poll answers. Note that multiple answers should be separated by \n also known as a "newline" character.
    avatar
    Guest
    Guest


    Solved Re: How can I add an automatic poll like here on the support forum?

    Post by Guest October 4th 2015, 4:29 pm

    Thank you, @Ange Tuteur. Also for sub-forums, am I suppose to do the same?
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: How can I add an automatic poll like here on the support forum?

    Post by Ange Tuteur October 4th 2015, 4:36 pm

    If you're applying this to multiple forums then I'd suggest this approach :
    Code:
    window.location.pathname == '/post' && $(function () {
      var forums = [1, 2, 3, 14],

      lang = {
        info : 'The poll will be added automatically.',
        poll_question : 'Do you agree or disagree ?',
        poll_answers : 'Agree\nDisagree'
      },

      i = 0,
      j = forums.length,
      f;

      if (document.post && document.post.mode.value == 'newtopic') {
        f = document.post.f.value;
       
        for (; i < j; i++) {
          if (f == forums[i]) {
            $(document.post.poll_title).closest('fieldset').html('<strong>' + lang.info + '</strong><input type="hidden" name="poll_title" value="' + lang.poll_question + '" /><input type="hidden" name="poll_option_text" value="' + lang.poll_answers + '"><input type="hidden" name="poll_length" value="30" /><input type="hidden" name="poll_cancel_vote" value="1" />');
            break;
          }
        }
      }
    });

    At the top is an array called "forums", it contains multiple forum ids that the script should be applied to. Make sure to separate each id by a comma. Wink
    avatar
    Guest
    Guest


    Solved Re: How can I add an automatic poll like here on the support forum?

    Post by Guest October 4th 2015, 5:07 pm

    Okay, thanks.
    topic solved
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: How can I add an automatic poll like here on the support forum?

    Post by Ange Tuteur October 4th 2015, 5:08 pm

    No problem. Wink

    Topic archived

    Have a good day. Smile