Skip Navigation

[Résolu] Create a Dropdown of users in a Toolset Form

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How can we create a Dropdown select Field of existing users in a Toolset Form and save the picked user in a custom field?

Solution:
It's natively not possible, but you can use some workarounds as described here https://toolset.com/forums/topic/dropdown-select-field-that-shows-all-users-on-front-end-post-form/#post-1340299

This support ticket is created Il y a 4 années et 7 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 8 réponses, has 2 voix.

Last updated by Laura Il y a 4 années et 7 mois.

Assisted by: Beda.

Auteur
Publications
#1340021
Select User for Report View.png
Post Form for Reports.png
FIRESH~1.PNG

Tell us what you are trying to do?
I'm trying to be able to add a select field for a Custom Post Type "Reports" that contains all users of a specific role (i.e. Affiliates) so that the user can select a user from the dropdown.

Is there any documentation that you are following?
I tried following this ticket :
https://toolset.com/forums/topic/create-a-select-user-drop-down-menu-field-to-link-one-custom-post-to-one-user/

But I don't know if I incorporated it correctly?
The CPT is "Reports".
There are only 2 fields so far A file upload field and this select field I'm trying to get users listed in it for a specific role "Affiliate".
I created a Field Group (attached) that only has the File field. I added the Select field by expert mode on the post front-end form using the generic-field from the example from the ticket i mentioned above.
Like this:
[credform]
[cred_field field='form_messages' class='alert alert-warning']
<div class="form-group">
<label>Final Report</label>
[cred_field field='final-report' force_type='field' output='bootstrap']
</div>
<div class="form-group">
<label>Affiliate Member: </label>
[cred_generic_field field='affiliate-member' type='select' class='' urlparam=''] { 'required':0, 'validate_format':0, 'persist':1, 'default':[], 'options':[ [wpv-view name="select-user-for-report" limit="-1" offset="0"] ] } [/cred_generic_field]

</div>
[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
[/credform]

But its not working and I'm kinda lost at this point on what to do?
All i get is the Label and no Select field displays on the page where the form is on. There are no errors in the browser either.

What is the link to your site?
hidden link

#1340299

It's not possible to produce a dropdown with all users on your system in a Toolset Form or Toolset Field in general unless you use workarounds or custom code, even the less for specified user roles.

For this to be present as a native feature in Toolset you'd have to suggest it to the Product Management here:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

The solution you found focuses on a workflow where you create a View, querying Users, and return a JSON valid output, holding data that can be used later in a Generic Toolset Form Field.

Now, to do that, you would need to:

1. Create a User view, full with the Custom Query to narrow down which users should be shown.
2. The View loop should be a raw output (there is a checkbox below the View's Loop Editor that allows you to return a raw View loop)
3. The loop content should be returning a valid JSON, see https://toolset.com/forums/topic/create-a-select-user-drop-down-menu-field-to-link-one-custom-post-to-one-user/#post-326720
4. The Toolset Form Generic Field will now show those users if populated with the Toolset View, but that doesn't mean it will save what's chosen anywhere yet.
For that, you'll need Custom Code, or using the (deprecated but still available) persist:1 attribute of the Generic Field.

I see you use persist, so the chosen user in the form will be saved in the affiliate-member field.
Note, it will work only if the View returns a real, clean and raw JSON as shown on the other ticket.

If you can't see the select field, or it's not populated, your view is not returning a valid JSON most likely.
Note that today we even have a GUI option when using the Loop Wizard, to return a delimited custom list, use that for "raw" and JSON output.

If all this does not work, can you add access to a testing object where I can amend some changes to showcase an example?

#1341333
Affiliate Admin Reports Page.png
Select-User-for-Report-View-2.png

Hello Beda -
thanks for responding...

1. Create a User view, full with the Custom Query to narrow down which users should be shown.

I created the User View "Select User for Report" with content selection checked the role "Affiliate" which is what I want in the select dropdown on the "Form for Report" form.

2. The View loop should be a raw output (there is a checkbox below the View's Loop Editor that allows you to return a raw View loop)

I only see a checkbox for "Disable the wrapping DIV around the View" is this the one you are speaking of? If so I checked it. (see attachment) OR Did you mean to check the "raw" button on the editor?

3. The loop content should be returning a valid JSON, see https://toolset.com/forums/topic/create-a-select-user-drop-down-menu-field-to-link-one-custom-post-to-one-user/#post-326720

That is the document/ticket I was trying to follow. I added the "User VIew for Reports" view to this page so we could "see": what it was returning: hidden link

4. The Toolset Form Generic Field will now show those users if populated with the Toolset View, but that doesn't mean it will save what's chosen anywhere yet.
For that, you'll need Custom Code, or using the (deprecated but still available) persist:1 attribute of the Generic Field.

I see you use persist, so the chosen user in the form will be saved in the affiliate-member field.
Note, it will work only if the View returns a real, clean and raw JSON as shown on the other ticket.

If you can't see the select field, or it's not populated, your view is not returning a valid JSON most likely.
Note that today we even have a GUI option when using the Loop Wizard, to return a delimited custom list, use that for "raw" and JSON output.

If all this does not work, can you add access to a testing object where I can amend some changes to showcase an example?

I think it would be a good idea for you to login and take a look around. This is only a dev site so you are free to play around with it to help me with this issue. There a a few test "Affiliate" roles users and the user to login as to "see" the Admin forms and views on the front end is

The Site Admin for you to be able to get to the WP dashboard is:

So you would need to login to these 2 accounts to see the results and to see the toolset backend.

Let me know if you need anything else.
Thank you!

#1341467
Affiliate Admin Reports Page-2.png

oh, also ... I don't know where the text '27 AdminReports' is coming from? i don't think I want that the is the current user which is not an "affiliate' role so not sure why this is being captured from the view? Se attached screenshot showing this.

#1341505

UPDATE!!! Ok... I kept working at this and I got the view to return valid JSON! I was able to upload a file and select the user and submit the form.... Now I check to see if it is saving the user and file in the CPT.... it is NOT saving anything to the CPT "Reports" .... Do you have any ideas why? You may login and look around it that helps.

#1341543

Ok now it IS saving CPT "Reports" with the selected user! Yay!

But can you look at the "Reports" CPT and see if I need to remove the the field group? Just wondering why it is showing the "Final Report" field two times... Did I set this up incorrectly?

thanks!

#1341803

1. Yes correct
2/3. That looks correct
4. This is a public forum, I deleted the access data. For testing, developping and debugging it's not ideal to have to navigate around permissions, or other restrictions. Please always if possible use clean slates when you start working on "functionality" or "logic", so once you get the "core" working you can always wrap it in any conditional you want, but first, the minimal technical structure must work.
This, in our case, is the JSON view and Generic Field in the form, nothing else should hence influence or depend it/on it.

I see meanwhile you corrected JSON and the field is saving, but I cannot check about your last enquery, since I cannot access the WordPress backend with the login detaiols provided, they are likely of a low user role.

I have enabled the private reply sections, however I think you achieved the goal. Please let me know if you need more help, and in that case you can attach the new login details in the next reply privately.

#1342611

The Field you see twice is one from WordPress Display and the other from Toolset Display.
You can remove the WordPress Fields in the Post Types settings, just uncheck "Support for Custom fields" in the options.
Toolset custom fields still are added but you won0t see the WordPress fields GUI anymore.

What you see with that field will happen with all fields of Types, since those are just custom fields, and if active, WordPress will display those values in its own filed editor (which as said can be deactivated).

Does that resolve the issue?

#1342701

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.