• Resolved markmidmo

    (@markmidmo)


    This is a simple membership database. Some members don’t want their phone number or email to display. There is a field show_phone where 1 = yes and 0 = no don’t display.
    Does this plug-in have a way to add that logic so I can control when a phone number or email is displayed?

    I’d like to display the value “No available” instaed of the phone number but honestly at this point I’d be OK if I could just skip showing any value if the result of the “show_phone” is off.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author xnau webdesign

    (@xnau)

    This is best done in a custom template for the shortcode display. Take a look at this article for the basic instructions on using custom templates:

    Using Custom Templates in Participants Database

    The idea is that in the loop that displays each field, when it’s time to display the phone number, you check the $this->participant_values array for the “show phone number” value. if they don’t want it shown, you change the value property of the field object so that it shows whatever you want it to show when the phone number is not displayed.

    I have a tutorial that explains how to do something that is somewhat similar that can help you understand how to make your custom template:

    Setting the Default Value of a Field in a Custom Template

    Thread Starter markmidmo

    (@markmidmo)

    I do not have access to FTP so cannot edit the file structure to create a folder. As this appears to be the starting point it looks like this solution won’t work for me. I guess I’ll have to look for another product to house the member database.

    Thread Starter markmidmo

    (@markmidmo)

    I’ve been setup to use the FTP and copied the pdb_single template. Renamed it custom and have added the template to the short code on the page.

    Is there a simple snipet of code I can add to the custom template to “see” that my setup works before I start trying to add logic?

    Thread Starter markmidmo

    (@markmidmo)

    I am almost there! I’ve created the custom template of the single record display. I copied the block that loops through the group & fields. At the very top I initialized a variable to show the phone number. In the block I copied I removed all the prints and did a test to see if the phone should print and updated the variable.

    Then I exit to the original While blocks to do the print. I’ve added some temp echo statements to see if things are working OK.

    I never enter the next WHILE block that does the print, even though it is the original code and I removed nothing.

    I’m thinking it is a counter or pointer that needs reinitialized as I have just processed the blocks in the new loop I put at the top. I find the RESET function but can’t figure out the name of the array that needs reset.

    Help???

    Thread Starter markmidmo

    (@markmidmo)

    P.S. If you look at my live code it look OK but that is because I have moved back in a temp version of the pdb.single.custom template that has hard coded “Not Available” on the phone number.

    • This reply was modified 5 years, 8 months ago by markmidmo.
    Plugin Author xnau webdesign

    (@xnau)

    You do not have to exit the while loop, just assign the string in the loop and print it. It’s very simple, you may be making it more complicated than it needs to be.

    
    <?php // here is our code to set the field value
       if ( $this->field->name === 'phone' && $this->participant_values['show_phone'] === 'no' ) { 
          $this->field->value = 'phone number not displayed';
       }
    ?>
    Thread Starter markmidmo

    (@markmidmo)

    I like that solution but have not been able to get it to work. Breaking it apart, the first part of the “And” works but I cannot get the “participant_values” section to work. In an attempt to debug it, I have reduced it to the following and it is never executed:

    <?php if ( $this->participant_values[‘show_phone’] === ‘No’ ) { echo “showphone No was found”; } ?>

    I’ve verified the field ‘show_phone” is correct, and the value in the database is ‘No’ not all lower case. I’ve tried it with ” around No as well as single quotes. I’ve tried === as well as ==.

    Any thoughts on what I have done wrong?

    Thread Starter markmidmo

    (@markmidmo)

    EUREKA! It works!

    To all those others looking for this solution but not proficient in php heed this warning…. You MUST use the correct quotes around fields. Here is my final result that does work. I was failing to put the double quotes around the field name in both places.

    <?php // here is our code to set the field value
    if ( $this->field->name === “phone” and $this->participant_values[“show_phone”] === “No” ) { $this->field->value = “Not Available” ; } ?>

    Plugin Author xnau webdesign

    (@xnau)

    thanks for sharing what fixed it…I was just going to point that out…

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Single Record display – conditional control of a field’ is closed to new replies.