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.
The forum of the forums
4 posters

    Sorting member to group upon registration

    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Sorting member to group upon registration

    Post by Kami-sama January 3rd 2017, 5:49 pm

    First topic message reminder :

    Technical Details


    Forum version : #phpBB2
    Position : Founder
    Concerned browser(s) : Google Chrome
    Who the problem concerns : Yourself
    Forum link : ( link is hidden, you must reply to see )

    Description of problem

    Soo hey!

    Is it possible to sort a person upon registration to a specific member group? A person would complete a test and based on the results he would be added to a specific group. If that is not possible, then maybe activating a certain profile field would?

    I imagine, that this could be done with an HTML page?
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 5th 2017, 11:09 pm

    The answers (same for both):
    Answer 1
    Answer 2
    Answer 3
    Answer 4

    So the IDs are:
    Q1 - field_id10
    Q2 - field_id12

    The script:
    Code:
    //Code by Luffy
    $(document).ready(function(){ 
      var a=$('dl#field_id10 .field_uneditable'), // id1
          b=$('dl#field_id12 .field_uneditable'); // id2
     
     //Question 1 Answers
      $('dl#field_id10 .field_uneditable:contains(Answer 1)').addClass('2ptsA'); // id1
      $('dl#field_id10 .field_uneditable:contains(Answer 2)').addClass('3ptsA'); // id1
      $('dl#field_id10 .field_uneditable:contains(Answer 3)').addClass('4ptsA'); // id1
      $('dl#field_id10 .field_uneditable:contains(Answer 4)').addClass('5ptsA'); // id1
     
      //Question 2 Answers
      $('dl#field_id12 .field_uneditable:contains(Answer 1)').addClass('2ptsB'); // id2
      $('dl#field_id12 .field_uneditable:contains(Answer 2)').addClass('3ptsB'); // id2
      $('dl#field_id12 .field_uneditable:contains(Answer 3)').addClass('4ptsB'); // id2
      $('dl#field_id12 .field_uneditable:contains(Answer 4)').addClass('5ptsB'); // id2
     
      if ( a.hasClass('2ptsA') && b.hasClass('2ptsB') || a.hasClass('2ptsA') && b.hasClass('3ptsB') || a.hasClass('3ptsA') && b.hasClass('2ptsB') ) {
        $('table#resultTest').addClass('groupA');
      } else if ( a.hasClass('3ptsA') && b.hasClass('3ptsB') || a.hasClass('2ptsA') && b.hasClass('4ptsB') || a.hasClass('4ptsA') && b.hasClass('2ptsB') || a.hasClass('4ptsA') && b.hasClass('3ptsB') || a.hasClass('3ptsA') && b.hasClass('4ptsB') || a.hasClass('2ptsA') && b.hasClass('5ptsB') || a.hasClass('5ptsA') && b.hasClass('2ptsB') ) {
        $('table#resultTest').addClass('groupB')
      } else if ( a.hasClass('4ptsA') && b.hasClass('4ptsB') || a.hasClass('3ptsA') && b.hasClass('5ptsB') || a.hasClass('5ptsA') && b.hasClass('3ptsB') || a.hasClass('4ptsA') && b.hasClass('5ptsB') || a.hasClass('5ptsA') && b.hasClass('4ptsB') ) {
        $('table#resultTest').addClass('groupC')
      } else if ( a.hasClass('5ptsA') && b.hasClass('5ptsB') ) {
        $('table#resultTest').addClass('groupD')
      }
    });

    After the answers are saved, I inspect the page but it does nit show appropriate classes assigned to the question tables.

    P.S. Wouldn't this work too?
    Code:
    var R=0;

    //Question 1 Answers
    $('dl#field_id10 .field_uneditable:contains(Answer 1)').sum(function(){
        R=R+1;
    });
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    In progress Re: Sorting member to group upon registration

    Post by TheCrow January 6th 2017, 9:42 am

    You did create the result field right?

    Also the script will work yes but you have to write the correct functions and the easiest way for me was with the classes but if you want you can change anything if you want! Smile



    Sorting member to group upon registration - Page 2 Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 6th 2017, 10:14 am

    Jup, the result is there.
    If you want, I can give you access Wink

    P.S. SO I was thinking about something like this:
    Code:
    $(document).ready(function(){
       var R=1;
       var a1="Answer 1",
          a2="Answer 2",
          a3="Answer 3",
          a4="Answer 4";

       var a = document.getElementById("field_id10").innerHTML;
       if (a == a1) {   
            R+=0;
        } else if (a == a2) {   
            R+=2;
        } else if (a == a3) {   
            R+=5;
        } else if (a == a4) {   
            R+=8;
        }
       
       if (R >= 15){
          $('#resultTest').css({"background-color": "red"});
       } else if (R >= 10){
          $('#resultTest').css({"background-color": "purple"});
       } else if (R >= 5){
          $('#resultTest').css({"background-color": "green"});
       } else if (R >= 0){
          $('#resultTest').css({"background-color": "blue"});
       }
          
    });

    What would be correct IDs? And let me know if there is anything else I can optimize in this code Wink
    Or should I just name the function and add the name in profile template?
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    In progress Re: Sorting member to group upon registration

    Post by TheCrow January 6th 2017, 1:50 pm

    I believe that's correct. Does that change the table background-color? If no please give me an account to check it live. (via pm please).

    Thanks!



    Sorting member to group upon registration - Page 2 Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 6th 2017, 2:03 pm

    Testing the script in HTML file it works, but in forum unfortunately not.
    I think the ID should be different. with the .field_uneditable

    I will send you an account login info via.
    Google translate should help you out, let me know if you cannot find something.

    P.S. Now the script is disabled, because it makes the top announcement disappear.
    P.P.S. This is updated script with .field_uneditable

    Code:
    $(document).ready(function(){
       var R=0;
       var a1="Answer 1",
          a2="Answer 2",
          a3="Answer 3",
          a4="Answer 4";

       var a = document.getElementById("field_id10").getElementsByClassName("field_uneditable")[0].innerHTML;
       if (a == a1) {   
            R+=0;
        } else if (a == a2) {   
            R+=2;
        } else if (a == a3) {   
            R+=5;
        } else if (a == a4) {   
            R+=8;
        }
       
       if (R >= 7){
          $('#resultTest').css({"background-color": "red"});
       } else if (R >= 4){
          $('#resultTest').css({"background-color": "purple"});
       } else if (R >= 1){
          $('#resultTest').css({"background-color": "green"});
       } else if (R >= 0){
          $('#resultTest').css({"background-color": "blue"});
       }
          
    });
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 6th 2017, 3:33 pm

    Sorry or double posting! But got it working!

    The issue now - when script is activated, the announcement block in most pages is no longer visible. Cannot figure this one out. The script does not have any similar elements.

    EDIT: so I figured, that the issue happens ONLY when this part is included. Any ideas why?
    Code:
       var a = document.getElementById("field_id10").getElementsByClassName("field_uneditable")[0].innerHTML;
    if (a == a1) {   
            R+=0;
        } else if (a == a2) {   
            R+=2;
        } else if (a == a3) {   
            R+=5;
        } else if (a == a4) {   
            R+=8;
        }
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 7th 2017, 7:41 pm

    So I have tried adding script directly to profile template - script working, but the announcement gone.

    Enabling script in all pages, makes the announcement gone in every page except te profile.
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    In progress Re: Sorting member to group upon registration

    Post by TheCrow January 7th 2017, 11:02 pm

    Which part exactly is the announcement block?



    Sorting member to group upon registration - Page 2 Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 7th 2017, 11:03 pm

    Everything above the menu, what you would call a logo.
    I will activate the script so you can see.
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    In progress Re: Sorting member to group upon registration

    Post by TheCrow January 7th 2017, 11:03 pm

    Okay now the script is not enabled?



    Sorting member to group upon registration - Page 2 Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 7th 2017, 11:05 pm

    I enabled it just now.
    You can see how the top is not visible in the homepage, portals and inside topics. Also, quick reply options (like font color and etc) no longer visible.
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    In progress Re: Sorting member to group upon registration

    Post by TheCrow January 7th 2017, 11:06 pm

    It gives an error with this in that script:
    Code:
    getElementsByClassName



    Sorting member to group upon registration - Page 2 Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 7th 2017, 11:09 pm

    Any idea how to overcome it?
    As mentioned above, I have tried adding JQ directly to template of the profile, but the logo/announcement is not visible then.

    P.S. Sorry for the spelling Very Happy issues with F G H keys.
    P.P.S. I just deleted that part and issue still persists.
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    In progress Re: Sorting member to group upon registration

    Post by TheCrow January 7th 2017, 11:14 pm

    Try this:
    Code:
      var a = document.getElementById('field_id10').getElementsByClassName('field_uneditable')[0].innerHTML;
    if (a == a1) { 
            R+=0;
        } else if (a == a2) { 
            R+=2;
        } else if (a == a3) { 
            R+=5;
        } else if (a == a4) { 
            R+=8;
        }
    I'm not really that good with javascript-ing and to be honest i would try things out in you position..



    Sorting member to group upon registration - Page 2 Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 7th 2017, 11:21 pm

    Same -.-
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    In progress Re: Sorting member to group upon registration

    Post by TheCrow January 7th 2017, 11:23 pm

    The one i gave you the first place doesn't work? Or you are just trying to do this with math phrases? Just to be sure here..



    Sorting member to group upon registration - Page 2 Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 7th 2017, 11:26 pm

    I tried the one you just posted. I have an idea. (google)
    Suggest to apply the script in the end of the page. So here it would be footer... Or end o body.
    TheCrow
    TheCrow
    Manager
    Manager


    Male Posts : 6916
    Reputation : 795
    Language : Greek, English

    In progress Re: Sorting member to group upon registration

    Post by TheCrow January 7th 2017, 11:28 pm

    The footer would be fine. I'll provide some more help tomorrow night because i have a trip in a few hours and i have to get to sleep. Smile



    Sorting member to group upon registration - Page 2 Thecro10
     Forum of the Forums

    Forumotion Rules | Tips & Tricks |
    FAQ | Did you forget your password?



    *** The Support Forum will never ask you for your email or password, so please do not post them anywhere! ***
    No support via PM!
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 7th 2017, 11:34 pm

    No go - same happens -.-
    Cool! GL on your trip Wink
    I will continue experimenting.

    OMG, I'm genius :DD added tis IF, to check if the page is USER profile.
    Code:
    if(document.URL.indexOf("http://hogas.huhohi.com/u") >= 0){

       var a = document.getElementById("field_id10").getElementsByClassName("field_uneditable")[0].innerHTML;
       if (a == a1) {   
            R+=0;
        } else if (a == a2) {   
            R+=2;
        } else if (a == a3) {   
            R+=5;
        } else if (a == a4) {   
            R+=8;
        }
       
       var b = document.getElementById("field_id12").getElementsByClassName("field_uneditable")[0].innerHTML;
       if (b == b1) {   
            R+=0;
        } else if (b == b2) {   
            R+=2;
        } else if (b == b3) {   
            R+=5;
        } else if (b == b4) {   
            R+=8;
        }
       
       }

    Okey, now some minor things left Smile
    I want this test and result to be separated from other profile fields in some way (different background color, image separator before/after). Any ideas how to do that?

    P.S. Let me know if I can optimize my script in any way.
    P.P.S. Is there a way to delete "no choice"? or the only way is by having default answer? Also, mods and admins can always see the questions, even i the answer is "no answer". BUT simple member does not see them. I the member does not see them, then the issue with not showing announcement appears. Soo. I guess we must have "default" option. ((Resoled with an if to check if the element exists, LOL))
    Kami-sama
    Kami-sama
    Forumember


    Female Posts : 407
    Reputation : 12
    Language : EN, RU, DE, LT
    Location : Lithuania

    In progress Re: Sorting member to group upon registration

    Post by Kami-sama January 12th 2017, 10:41 pm

    UP

      Current date/time is September 22nd 2024, 6:38 pm