How to use checkbox to agree to be included in Membership List

Try using both search and search_columns. Unless something has changed recently, s2member-profile can definitely search s2Member custom registration fields.

[s2Member-List search_columns="s2member_custom_field_membershiplist_permission" search="2member_custom_field_[membershiplist_permission="1" /]

The syntax needed for this to work as expected is as follows, assuming you created a Custom Registration/Profile Field in s2Member as a checkbox, with a Unique ID of agreed_to_terms.

[s2Member-List enable_list_search="yes" search_columns="s2member_custom_field_agreed_to_terms" search="1" /]

That will display only those users who checked the box. A checked box has a value of 1 in the DB.


Note: Searching for the opposite in this case, will, unfortunately, not work; e.g., trying to list users who did not agree results in a seemingly mysterious set of results.

...  search="0" /] (does not work).

The reasons searching for 0 will not work.

  • By default, PHP considers 0 to be empty, which is the same as not entering a search term at all.
  • Even if we interpret 0 as being the integer value instead of being empty, it would still not work as you might expect. The reason is that internally an unchecked box has no value. Only when the box is checked does an entry appear in the DB that would be searchable.
1 Like

Using the same agreed_to_terms field ID as an example, you can also build conditionals that check for the box being checked (or not). This is accomplished using a combination of our ezPHP for WordPress plugin, and the get_user_field() function that comes with s2Member.

<?php if (get_user_field('agreed_to_terms')) : ?>
   Display content here, the box is checked.
<?php else : ?>
  Whatever you want to show.
<?php endif; ?>

In the opposite…

<?php if (!get_user_field('agreed_to_terms')) : ?>
   Display content here, the box is NOT checked.
<?php else : ?>
  Whatever you want to show.
<?php endif; ?>
1 Like

Jason, it always makes so much sense when you explain things! Thanks!

1 Like

:smile: Thx Tim. I’m just glad I could help.

Thank you so much to everyone who helped!! It worked beautifully. Just in case anyone else if interested in the working code, I’ll list it below. Again- thanks Pat, Tim, and Jason!

The features of this Membership List are:

  • the list is divided by levels of membership
  • I’ve included anchors to jump up and down the list to specific levels.
  • only those members who give permission are included You do this by:
  1. Go to S2Member (Pro)/General Options/Registration-Profile Fields &Options/Add New Field.

  2. Create a “Checkbox (prechecked)”

  3. Make the “Field Label/Description” something like “I agree to my name, email, and place of employment being included in the Membership Listing page (accessibly by logged-in, paid members only).”

  4. Make the “Unique Field ID” this: “membershiplist_permission”

Here is the code for you to use and modify:

The Membership Listing page is viewable by current members only. Inclusion in the list is optional and you can change your preference through your profile. Inappropriate use of members emails will not be tolerated.

  [s2Member-List-Search-Box action="" placeholder="Search Members..." /]
<hr>
<a name="flmb"></a>
</a>Jump down to <a href="#stmb">Student Members</a> | <a href="#rtmb">Retired Members</a> | <a href="#afmb">Affiliate Members</a>

<h2>Full Members:</h2>
[s2Member-List enable_list_search="yes" levels="4" search_columns="s2member_custom_field_membershiplist_permission" search="1" show_fields="email,employer_name" orderby="last_name" order="ASC" /]
<hr>
<a name="stmb"></a>
<h2>Student Members:</h2>
[s2Member-List enable_list_search="yes" levels="1" search_columns="s2member_custom_field_membershiplist_permission" search="1" show_fields="email,employer_name" orderby="last_name" order="ASC" /]
<hr>
<a name="rtmb"></a>
<h2>Retired Members:</h2>
[s2Member-List enable_list_search="yes" levels="3" search_columns="s2member_custom_field_membershiplist_permission" search="1" show_fields="email,employer_name" orderby="last_name" order="ASC" /]
<hr>
<a name="afmb"></a>
<h2>Affiliate Members:</h2>
[s2Member-List enable_list_search="yes" levels="2" search_columns="s2member_custom_field_membershiplist_permission" search="1" show_fields="email,employer_name" orderby="last_name" order="ASC" /]

</a>Jump up to <a href="#flmb">Full Members</a> | <a href="#stmb">Student Members</a> | <a href="#rtmb">Retired Members</a>
1 Like

Ok, one more issue :slight_smile:.

The search form box does not work at all. Yesh. I’ve experimented and no matter what, it says there are 0 results in each of the level categories. In the address bar it says "www.--------.com/membership-listing/?s2-s=Jane+Doe

Perhaps that is a clue as to why the search form it isn’t working?

I’ve been trying to solve why the search box is not working. Strangely, if I try to search for “1” or “0” then the search box returns with all members! Could it be because I used search_columns in the S2Member-List code? If I search for a name of anysort, then it comes back as zero.

Is there some shortcode that I should include in this line: [s2Member-List-Search-Box action="" placeholder="Search Members..." /] that makes the search function work?

Hi Keith.

Did you resolve this. I’m trying to do the same thing and finding that the custom field can’t be used as a filter along with another filter for member fields (custom or otherwise!)

Andy

Andy (and Keith). I used the radio-button-multi-option to solve this same need without using PHP The question prompt reads “I want to be in the directory” and the options are yes and no. using the pipe | allows the webmaster to choose both the option value (what you will use to filter behind the scenes) and the “option label” (what the user sees when they choose which box (really circle) to check. HERE IS THE PART that makes no sense, but MAKES IT WORK: the software needs to have a ccaps filter, even if you add in all your ccaps so it doesn’t limit the output.

[s2Member-List orderby=“last_name” order=“asc” s2member_custom_field_directory_public search=“public-directory” show_fields=“Name:full_name,last_name, email, phone,phone2, city” limit=“100” ccaps=“annual,lifetime,autorenew,executive” rlc_satisfy=“ANY” avatar_size=90 /]

But Jason @jaswrks , can you tell me why my output will not orderby?

@daleandy, @MASP

Hi MCBA

I have to say that I admitted defeat on the basis that it is too hard to achieve in S2Member with the limitations of the functionality. Instead I installed plugin “AMR Users” which integrates with S2Member custom fields and presents a public directory. It worked perfectly and with greater options and functionality than I’d originally required.

It does however mean that I do not need the Pro licence, but that’s life. J

Thanks, @daleandy ! I will check out AMR Users. I have S2Member Pro on two sites, helping two non-profits with over 1,000 members. I’m hoping that @jaswrks can straighten me out on the orderby and search of that list (right now the search pulls from entire data base instead of just the custom_field search.)

I shall watch this thread to see whether you get a solution, but I went thought the exact same issues and came up blank. What you in effect want is the custom field to be treated like a ccap field, but S2Member treats them very differently.

Took me an hour to get AMR Users to do what I wanted. Don’t get me wrong, S2Member is great and a key part of my social group site functionality, but it has been hard to get the member directory issue resolved, and interfacing seamlessly with mailchimp took a lot of code in a S2hacks MU plugin.

Good luck.

Andy

@daleandy Andy, which AMR additional plugins did you buy?

AMR Users. Free version was fine to do a good member directory integrating with the S2Member custom fields.

@daleandy Thanks or finding AMR plug-in for me. I am playing with AMR now. I need filtering, which requires +plus addon, unless, as AMR suggests, I may be able to get away with an HTML filter, if I can figure it out.

FROM THEIR WEBSITE:
Simple Filtering
If you have some very simple filtering needs, you could code your own little form html to sit on the same page. The html should pass the following parameters back to the user list page.
Yes – this can also be done as links from other pages.

QUERY STRING PARAMETERS:
filter=hide or show
activate filtering request. plugin will then look for column names
hide says “hide that column” – as all rows will have the same value
show = “show the column”
column_name=value
pass the technical column name (see the ‘nice names’ list in the settings) and the value to be selected

I just had a need to allow a public directory with users who had agreed to be searched, being searchable by last name, and 3 other fields. There was no filtering of results for me. To ensure that only anyone who had agreed to be searched could themselves search, I included a PHP IF statement against the custom field checkbox. I understand why you may need to additional features. Works great but you do need to read the documentation as it not very intuitive at all!

Andy

so wait, you ARE filtering based on if they agreed to be searched. How ?

Hi MCBA.

OK, that’s why I say the documentation is difficult, as you can do much of what you want without any extra bought functionality I think. I had to work it out thought!

Firstly - to filter a search based upon those who have agreed to share their details:-

So, using AMR Users I use the Member Directory option. Using the Include/Exclude tab, specify the tick box field you have and then check the box that says exclude if blank :grin: This will only list those in the directory who have ticked the box. However, to get that option in the include/exclude, you have to include the tick box field first in the field display options under the fields/sort tab. The clever bit that took some reading, is that once you’ve included the field in the include/exclude tab as above, you can then go back and remove it from the fields/sort tab so that it is not visible in the search results. It still stays in the include/exclude tab. It takes a careful read of the documentation and some googling to make sure you can do what you want.

Secondly - to only allow those who have agreed to share their details to see others, I installed EzPHP to allow me to include PHP code on my page mixed in with shortcodes. I then did an IF statement which checks whether the current user logged in and using the page has ticked the box (my custom field is called “sharing”):

[php] if(get_user_field(‘sharing’)) : [/php]

In the search box you can enter leaving year, city, country or last name. Only signed-up users who have agreed to share their details will appear in search results:

[userlist list=2 start_empty=1]

[php] else : [/php]

**Sorry, but you set your profile on the basis of not sharing your information and so you can’t use this tool. **

Don’t despair, you can change this option by editing your profile!

[php] endif; [/php]

The “start_empty” attribute is a nice feature which prevents the list from displaying anything without any search criteria, which I wanted.

Hope this helps.
Andy

1 Like

Wow, Andy. Thanks so much for taking the time to write all that out for me!
I did see the document you where you got that info but I got confused because my “Filters” tab is grayed out.
I’ll give it another run.