After weeks of work I’m finally at the point I need to just ask for help here.
I have a CMS that is built around Formidable. There is a client portal page that shows their info dynamically from many different forms submitted at different times tagged with their user id. I then use that one variable to call all the displays for each individual logged in user. I need to be able to pick a user from a dynamic dropdown list and then show their info on the next page exactly like their client portal, but for the admin side with edit links. How can I accomplish this without currently having to log in as each user to see what they see?
Thank you for everything!
Ben




September 22, 2012 at 10:30 pm
I too would greatly appreciate the answer to this question
September 24, 2012 at 8:20 am
This requires a bit of custom code. It sounds like you already have a row in your custom displays to show entries for current user. Here's an example of custom code to get a different user id from the URL.
http://formidablepro.com/knowledgebase/frm_where_filter/
We don't have a built-in way of creating a drop down list of all users on the front end of your site. Custom code can be used to switch the user ID field to a drop down on the front-end too, but it's definitely not the easiest option.
September 24, 2012 at 9:38 am
This may not work either, but could this be accomplished using the post author ? If a user id is only associated with one author (display name?), then a drop down that has a selection of authors and, when one is selected, displays a list of all posts by that author, wouldn't that accomplish the same thing?
September 24, 2012 at 9:45 am
As long as you have a dropdown of users with the user ID as the value, it doesn't matter how it's generated.
September 24, 2012 at 10:20 am
Thank you for the direction on this task! I have already applied the correct filter to allow for a user ID dropdown (below added to functions.php). I'll reply back when I can set up this new code for the user ID specific display.
// Formidable - User Dropdown
add_filter('frm_setup_new_fields_vars', 'show_user_dropdown', 15, 2);
add_filter('frm_setup_edit_fields_vars', 'show_user_dropdown', 15, 3);
function show_user_dropdown($values, $field, $entry_id=false){
if($values['type'] == 'user_id' and !is_admin() and current_user_can('administrator') ){
$values['type'] = 'select';
$values['options'] = FrmProFieldsHelper::get_user_options();
$values['use_key'] = true;
$values['custom_html'] = FrmFieldsHelper::get_default_html('select');
if(!$entry_id){
global $user_ID;
$values['value'] = $user_ID;
}
}
return $values;
}
September 24, 2012 at 10:24 am
Thanks, Wisteriapro! If you could post the solution you come up with that would be a great help to the rest of us! I think I'm trying to accomplish the exact same thing you are.
September 24, 2012 at 1:23 pm
Stephanie...
I can't get it to function with the url. I've added the filter to my functionsphp page and set the user ID field correctly. I'm passing the user id field through a form in a url redirect, adding "?member=ID". What am I doing wrong?
The frm_where_filter also filters out the display for any user that sees the display whereas the url must include their user id to show it. Am I correct?
September 24, 2012 at 5:03 pm
What is the exact code you've added for frm_where_filter?
September 25, 2012 at 12:17 am
I've added this to the functions.php:
// Formidable - Change user ID used to filter entries
add_filter('frm_where_filter', 'filter_custom_display', 10, 2);
function filter_custom_display($where, $args){
if($args['where_opt'] == 730){
$user_id = $_GET['member'];
$where = "meta_value = ". (int)$user_id ." and fi.id='". $args['where_opt'] ."'";
}
return $where;
}
Then I created a form that passes the user id into the url so that it reads:
mysite.com/client-portal/?member=ID
The filter DOES function correctly, but with two caveats. What I've found is that the url parameters will only recognize the WordPress user number, not the ID that Formidable sees. Entering the number of the user after "?member=" works perfectly. I'm just not sure how to get the number of the user passed into the url from the form though. The second problem is a potential security issue with the filter because users would able to see another user's entries by just changing the ID number.
Thoughts?
September 25, 2012 at 7:11 am
Just a thought, but could there be a variable added to the filter to check if it is a certain page id? That would totally solve the problem with client displays.
September 25, 2012 at 11:06 am
Alright, I took the dive and tried my hand at filtering the page:
if(($args['where_opt'] == 730) and (is_page(1518))){
This worked perfectly on my admin only page and prevents anyone else from being able to inject their own "?member=ID" into the url. Now all I need to do is figure out how I can pass the user ID number into the url on the admin page.
September 25, 2012 at 11:46 am
You can also use current_user_can('administrator') if your question is how to prevent people from accessing someone else's info.
What url are you referring to? It is in a custom display?
September 25, 2012 at 12:16 pm
Thank you Stephanie! Limiting by admin rights is better. I was having no luck with that because I was using is_admin instead. The current_user_can('administrator') is perfect.
I have a form with the user dropdown. Upon submit it redirects to a url with the following settings:
mysite.com/client-portal/?member=[776]
776 is the field ID of the user dropdown in the form. It returns the url with the username of the user. The filter to show the entries is looking for the number of that user, not the username. My question is about obtaining the user number with my form.
September 25, 2012 at 12:56 pm
You can use [776 show=id]
September 25, 2012 at 1:33 pm
Thank you again for your dedication to go above and beyond normal helpdesk service! Everything works perfectly now. Where do I send donations?
Lauren:
To help put everything in perspective, I did the following steps...
1) Add the filter in functions.php to allow the usernames to appear as a dropdown to the admin.
// Formidable - User Dropdown
add_filter('frm_setup_new_fields_vars', 'show_user_dropdown', 15, 2);
add_filter('frm_setup_edit_fields_vars', 'show_user_dropdown', 15, 3);
function show_user_dropdown($values, $field, $entry_id=false){
if($values['type'] == 'user_id' and !is_admin() and current_user_can('administrator') ){
$values['type'] = 'select';
$values['options'] = FrmProFieldsHelper::get_user_options();
$values['use_key'] = true;
$values['custom_html'] = FrmFieldsHelper::get_default_html('select');
if(!$entry_id){
global $user_ID;
$values['value'] = $user_ID;
}
}
return $values;
}
2) Create a form for clients with a hidden user id field so that it captures it in the entry.
3) Create a custom display/page from the client form that uses the “Advanced” box of the custom display settings to only show the entries of the current user.
4) Add filter in functions.php
// Formidable - Change user ID used to filter entries
add_filter('frm_where_filter', 'filter_custom_display', 10, 2);
function filter_custom_display($where, $args){
if(($args['where_opt'] == USER ID FIELD FROM ENTRY) and (current_user_can('administrator'))){
$user_id = $_GET['member'];
$where = "meta_value = ". (int)$user_id ." and fi.id='". $args['where_opt'] ."'";
}
return $where;
}
5) Create a form with only a hidden user id field, turning off email updates and data saving. The "Action After Form Submission" is changed to "Redirect to URL" and the following address written in:
website.com/custom-display-page/?member=[USER ID FIELD FROM FORM show=id]
Those steps made it possible for me to pick a user and see the display page they see so I can filter only their info and also easily print it. Good luck!
September 25, 2012 at 1:40 pm
Thanks so much for the detailed instructions. If you want to throw a donation our way, we won't turn it down. Thanks so much!
http://formidablepro.com/donate/
September 26, 2012 at 11:31 am
Got your donation. Awesome! Thank you!!!
September 27, 2012 at 9:03 am
Wow! Sorry for my tardy reply. This is impressive. Let me be sure I understand this correctly - this will allow me to have a page on the -front end- that only the admin can see, that includes a drop down of all users so they can select and view a specific user's profile?
September 27, 2012 at 9:55 am
Yes, Lauren, that is correct. As long as you are limiting who can view that page by a plugin or php script, only admins will see the form and get directed to the profile view.
I am willing to guide you along with what I've done on my end in case you hit a snag...if that is okay with Stephanie. I'll check back here daily to see if you have questions. :)
September 27, 2012 at 10:19 am
Oh you are too nice! Thank you! This task has been overwhelming for my very limited knowledge of php and scripting, but maybe with your (and possibly Stephanie's?) help I can get it done.
So y'all both understand, here is a general idea of what I'm trying to accomplish (I apologize for the length in advance):
I'm creating a site for a pet sitter, and she needs for all of her clients to be able to register on her site. Registration will allow them to accomplish the following:
1. Create a client profile, including their phone numbers, address, and their spouse / partner's information (name and email will be collected during the actual registration, which I'm using a gravity form for since it already has the email and password confirmation (with strength meter) built in).
2. Create entries for their 1. their emergency contact information (family member, friend, neighbor, etc.); and 2. their veterinarian's information.
3. Create separate profiles for each of their pets
Each of these "profiles" will use a custom post type that I have created using the Types / Views plugin (they recently released a plugin that allows users to create / edit / delete posts, but it was only released yesterday and does not have any conditional logic support yet).
Now, when a user logs in to the site, they should only be able to view and edit their information, obviously.
For the pet sitter, she does not want to have to mess with the back end of WP (understandably). She needs to be able to log in with her own credentials (as an admin), and to be able to quickly access any and all of the profiles created while she's on the go (from her iphone). I'm using Types / Views for the custom post types because it allows you to set one post type as the child or parent of another - so each client's pets would automatically be associated with the client, etc.
So, say she's on her own special page where she can access all of the information. There would be a big drop-down menu from which she could select a client's name - John Smith, for example. When she selects John Smith, it will pull up a page with an overview of all of his "posts" (like excerpts, I assume). She would be able to click and view his entire client profile, or his emergency contact's information, or his vet's information, or view any of his pets' profiles - where she could see instructions about medications, feeding schedules, medical conditions, etc.
I purchased Formidable because I saw that it had the post editing capabilities that gravity forms lacks. I really need to understand if Formidable, in combination with the other plugins I have (I have a developer license for GF, s2member pro, and Types / Views with Types Access) will allow me to accomplish this.
Any and all help will be appreciated enormously, and I will be happy to donate to whoever can help me figure this mess out.
So, wisteria, would the solution you worked out in this thread create the drop down menu from which Shannon could access all of the client's posts?
September 27, 2012 at 1:14 pm
It sounds like using the custom code above to create a dropdown is unnecessary. Since each person will only have one entry in the profile form, you can create a custom display to list the users who have submitted that form, and add a link in the content box with the user ID included.
Can you please get started on putting your forms together and let us know when you are to the point of having more specific questions?
@wisteriapro, you're more than welcome to help others, but you might want to ask for payment. =)
September 27, 2012 at 1:40 pm
Well actually, Stephanie, they won't only have one post; there will be multiple for each user: the client profile, the emergency contact profile, the veterinarian profile, and then however many pet profiles they create. So there would be a minimum of 4 "posts" total for each user.
And yes, I will repost here as soon as I get my forms together and have more specific questions. Like I said, I just wanted to give a general overview so that it was clear what I was trying to accomplish, and also to try to find out if this was outside of the scope of Formidable.
September 27, 2012 at 2:03 pm
It sounds like it's all doable. Will all of those profiles be in the same form, or different forms? I'm just saying it sounds like you will have one entry per user in the client profile form.
September 27, 2012 at 2:18 pm
They will be different forms. And to further complicated it, I need to place limits on a user's ability to create new posts with some of the forms. For example: once a user completes the Client Profile form and creates that "post," I don't want them to be able to add another one of those, only to edit the existing entry. The same thing with the veterinarian information form. The emergency contact and pet profile forms would be open to multiple submissions from the same user, because people could have several emergency contacts (i.e. Mom, Aunt Jane, Sally the neighbor, etc.). It would be nice, if possible, to put a cap on those, however. Say, limit the emergency contact form to 5 entries per user? (They would, of course, be able to edit all of their entries).
Do I understand correctly that you have to create one form for creating a post, and another form for editing an existing post? Or is creating and editing handled by the same form?
September 27, 2012 at 3:49 pm
That sounds like a fairly simple setup compared to mine. I have 8 forms that my clients fill out and each one builds into custom displays that show parts of their info on a single page. All of this I am now able to see client-specific through this new setup.
Your goal for having the pet sitter see a drop-down revolves around steps 1 and 5. Actually displaying the information depends on how you store and retrieve it from each user.
Upon registration they must be automatically entered into the WordPress User list. If a 3rd party is creating a separate user group, then it won't work. I'm using the VERY powerful eMember plugin that ensures a WP User is created alongside the secondary registration system.
Any information you gather from them that you wish to retrieve in a custom display must be gathered separate from the registration process since that is not part of Formidable. You could grab certain parts of the entries, but it does involve knowing the database field names of them. In my opinion it is best to keep everything within Formidable after basic registration.
Any time you gather info through a form, be certain to collect their User ID so it can be grabbed with the custom display (steps 2 and 3). This will allow you to reveal only those specific user's entries on a single page to the admin. It also gives you the power to allow users to view and edit their own data quite easily.
As for posts and other features of Formidable, you can always search the Knowledge Base and Help Desk for the answers. It's not my place to answer those questions. You may need to start a new thread if you don't find clues anywhere else.
Hope that helps!
September 27, 2012 at 3:58 pm
You can accomplish this by setting the form to allow only one entry per "logged-in user". This works even if the form is "registering" the user. This option is found on the form settings page.
Here is some information on limiting the total number of entries: http://formidablepro.com/knowledgebase/action-hooks/frm_display_form_action/#kb-limit-total-number-of-entries
The same form can be used for creating and editing posts.
Topic closed.