Skip Navigation

[Resolved] Cannot add a field to front-end submission form where a WP user can be selected.

This support ticket is created 8 years, 1 month ago. 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 5 replies, has 2 voices.

Last updated by Beda 8 years, 1 month ago.

Assisted by: Beda.

Author
Posts
#378401

I would like to add a WP user dropdown field to front-end submission form.
By default each post type has author.
I would like to add another user field ie. "responsible user:" and select the user from WP user list.
How is it possible?

#378474

I am not 100% sure I understand your request fully.

Do you want this field to be present on a CRED Create New Post Form?

You will need a List of users to populate the Types POST Field, which is not possible without Custom Coding.

What you can do is use Views in a non intended way.

You can generate a Valid JSON output with a User View (displaying users) and populate a Generic CRED Select Field with this.

Then, with a CRED API Code you can grab the value from that Field and update a Field created with Types.

This will allow you to add users and those will automatically also appear on the CRED Select Field.
But it will require careful coding of your View and a custom Filter applied to it.

Then, you will also use a CRED API Code to update the Post Field for the Backend with it.

Or, you can create a Select Field directly with Types and manually enter all Users as options in the Types > Fields > Add/Edit Field settings

Please let me know which way you want to go

Thank you

#378518

You understood well!

Is this user dropdown field in your Roadmap also? When do you plan to come out with that?

The first solution. Do you have this kind of code samples for API?

The second described solution is not a good option for us.

How do you see the following workaround?
Installing the plugin https://wordpress.org/plugins/advanced-custom-fields/
Setting up a custom field "user". Which is already user list dropdown.
Adding that custom field to CRED form and Backend form.
Would it be possible? Any threats?

Thanks!

#378576

We do not have any plans to add a Custom Field that is automatically populated with WordPress users.

It requires a huge new setup.
What should be returned there?
The ID; the Email, the username...?

How should it be rendered? which roles should be returned?

Please let me know what you think in regard, so I can eventually escalate a request.

As for now please follow this instructions:

1. Create a user View

2. This (or similar) in the loop:

<wpv-loop>[wpv-item index=1]{"value":"[wpv-user field="ID"]","label":"[wpv-user field="user_login"]"}
      
[wpv-item index=other],{"value":"[wpv-user field="ID"]","label":"[wpv-user field="user_login"]"}
</wpv-loop>

3. Apply this Filter to this View in functions.php:

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
 
function prefix_clean_view_output( $out, $id ) {
if ( $id == '375' ) { //change this View ID accordingly 
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if ( 
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
}
}
return $out;
}

IMPORTANT NOTES ON THIS FILTER ABOVE:
- It hooks early in the View output.
- Priority 5 is mandatory as we already do some other cleaning at priority 10.
- It only affects a View with an ID of 375, adjust acordingly if needed.
- It only affects Views with actual results: if the View matches no result, the same “No items found” or whatever you have between the wpv-no-items-found shortcode applies.
- It returns only what is between the HTML comments <!– wpv-loop-start –> and <!– wpv-loop-end –> , excluding them. Only content between those HTML comments is returned, as is.

Notice that, with this applied to a given View ID:
- Pagination, specially AJAX pagination, will not work.
- Parametric search, specially AJAXed parametric search, will not work.
- Other future features will not work either.

4. In the CRED form use this (or similar):

[cred_generic_field field="user" type="select" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":[],
"options":[ [wpv-view name="All WP Users"] ]
}
[/cred_generic_field]

5. Then use the CRED API and craft a Custom PHP code to update the Types Field so you will have this editable in the backend too.
https://toolset.com/documentation/user-guides/cred-api/#csd

This is what you can do currently with Toolset.

Other Plugins might provide user Select Lists as Custom Fields, but we can not support this, it will need some tests first.

Advanced Custom fields presents problems with Toolset because that plugin sometimes stores Fields in a very unusual way, not following strict WordPress Codex.

Thank you

#379020

Thanks for your guidance!
Please give some time to work through and test that.

#379094

Sure.

Please let me know if you have further questions regarding the issue mentioned in this Thread and let me know if the above solution works for you, I look forward to your reply!

Thank you for your patience.

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