Display Multiple selection custom profile fields?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mac Write
    Senior Member
    • Oct 2001
    • 666
    • 4.2.x

    Display Multiple selection custom profile fields?

    I can display a custom profile field fine in the postbit, but I want to have a condition is only 1 option selected then display Provider else if more then one option display Providers: and then list all the selected options. I am using checkboxes.

    Field 5 and 5 options. I don't know how to make the condition compact like If field only is 1 or 2 or 3 display else if field is multiple selections then display different text and all select options

    Also how do I get the ______ above the signature to display if signature present AND OR custom profile field entered?

    Also how do I get it to display the checkbox value (Provider name) instead of the number value?
    Last edited by Mac Write; Wed 10 Mar '04, 10:37pm.
  • Jake Bunce
    Senior Member
    • Dec 2000
    • 46598
    • 3.6.x

    #2
    Originally posted by Mac Write
    I can display a custom profile field fine in the postbit, but I want to have a condition is only 1 option selected then display Provider else if more then one option display Providers: and then list all the selected options. I am using checkboxes.

    Field 5 and 5 options. I don't know how to make the condition compact like If field only is 1 or 2 or 3 display else if field is multiple selections then display different text and all select options
    The options that are selected for multiple choice checkbox fields are recorded using a binary scheme. If the user has only one option selected then the number stored for the profile field will be an integer power of 2 (1,2,4,8,16). If the user has no options selected then the field will be blank (not 0, just blank). If the user has more than one option selected then the number stored will not be an integer power of 2.

    The conditional code would look something like this:

    Code:
    <if condition="$post['fieldX']">
    
    	<if condition="$post['fieldX'] == 1 OR $post['fieldX'] == 2 OR $post['fieldX'] == 4 OR $post['fieldX'] == 8 OR $post['fieldX'] == 16">
    
    		Provider: $post[fieldX]
    
    	<else />
    
    		Providers: $post[fieldX]
    
    	</if>
    
    </if>
    You can probably shorten that long condition with a modulo or something, but either way works.

    Originally posted by Mac Write
    Also how do I get the ______ above the signature to display if signature present AND OR custom profile field entered?
    The code for that separator is in your postbit template:

    Code:
    		<if condition="$post['signature']">
    		<!-- sig -->
    			<div>
    				__________________<br />
    				$post[signature]
    			</div>
    		<!-- / sig -->
    		</if>
    You can change the condition to:

    Code:
    		<if condition="$post['signature'] OR $post['fieldX']">
    Originally posted by Mac Write
    Also how do I get it to display the checkbox value (Provider name) instead of the number value?
    That's a problem. These types of profile fields are displayed correctly on profile pages so I looked in member.php for the code that handles this. This appears to be the code that handles this:

    Code:
    	if ($profilefield['type'] == 'checkbox' OR $profilefield['type'] == 'select_multiple')
    	{
    		$data = unserialize($profilefield['data']);
    		foreach ($data AS $key => $val)
    		{
    			if ($userinfo["$profilefieldname"] & pow(2, $key))
    			{
    				$profilefield['value'] .= iif($profilefield['value'], ', ') . $val;
    			}
    		}
    	}
    You will need to use this code for your application somehow. For help with this you will need to post on www.vbulletin.org

    Comment

    • Floris
      Senior Member
      • Dec 2001
      • 37767

      #3
      Amazing Jakeman! Thank you.
      I just learned something new and updated a few little things in my templates to speed things up and organize them better.
      /me can't wait for a conditional tutorial

      Comment

      • Mac Write
        Senior Member
        • Oct 2001
        • 666
        • 4.2.x

        #4
        I want it to display all the checked values

        Example; Provider: Fido or Provider Fido and Rogers, or Provider: Fido, Rogers and Telus.

        How do I get it to display that? I don't want to hack. It should a template mod at most.

        Comment

        • Jake Bunce
          Senior Member
          • Dec 2000
          • 46598
          • 3.6.x

          #5
          Originally posted by Mac Write
          I want it to display all the checked values

          Example; Provider: Fido or Provider Fido and Rogers, or Provider: Fido, Rogers and Telus.

          How do I get it to display that? I don't want to hack. It should a template mod at most.
          The problem is the way these types of profile fields are represented in the database. The represented value needs to be converted. The code to do this is in my previous post, but that code is taken from member.php and does not stand alone.

          You might be able to get by with just using the phpinclude_start template and no file modifications, but either way this requires custom code so you will need to post on www.vbulletin.org for help.

          Comment

          • Jake Bunce
            Senior Member
            • Dec 2000
            • 46598
            • 3.6.x

            #6
            And I agree that this should be a template mod at most.

            Comment

            • Mac Write
              Senior Member
              • Oct 2001
              • 666
              • 4.2.x

              #7
              I could to

              Code:
              <if condition "$post['fieldx'] =="1">
              Option 1
              <elsif condition "$post["field'] =="2">
              option 2
              Does it stop if the first if is met? or can I make it look at all of them and only display the ones that are valid?

              Comment

              • Jake Bunce
                Senior Member
                • Dec 2000
                • 46598
                • 3.6.x

                #8
                Originally posted by Mac Write
                I could to

                Code:
                <if condition "$post['fieldx'] =="1">
                Option 1
                <elsif condition "$post["field'] =="2">
                option 2
                Does it stop if the first if is met? or can I make it look at all of them and only display the ones that are valid?
                Yes, that code will stop if the first condition is met. And that code should be:

                Code:
                <if condition="$post['fieldx'] ==1">
                	Option 1
                <else />
                	<if condition="$post['fieldx'] ==2">
                		option 2
                	</if>
                </if>
                If you want all conditions to be checked then you would use this code:

                Code:
                <if condition="$post['fieldx'] ==1">
                	Option 1
                </if>
                
                <if condition="$post['fieldx'] ==2">
                	option 2
                </if>

                Comment

                • Pseudomizer
                  New Member
                  • May 2002
                  • 11

                  #9
                  Perfect. Thanks for this useful information. Helped me a lot.

                  Cheers,

                  Pseudomizer

                  Comment

                  widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                  Working...