The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Post Staus by User Role

Labels

This Discussion is public

Notifications

I am trying to create a form that creates posts that can be filled in on the frontend. I'd like for the 'post status' to change depending on the user role. For example if it is:

  • Author - post status=draft.
  • Subscriber - post status=publish.

I have tried creating a separate dropdown field that conditionally shows when the user role is, for example, a subscriber. This dropdown field has a value 'Published' and a separate value of 'publish'

I've then added a dynamic default value to the Post Status field of [frm-field-value field_id=1304 user_id=current] - which is the field id of the dropdown field above. However, when I submit the form it is still showing as Draft instead of Publish.

Is there a way to achieve this, ie. changing the post status depending on what the role of the user is who is completing the form? Thanks in advance.

I think you would have to have some might complicated custom code to accomplish this because on the surface at least, it goes against the way WordPress works.

When Formidable creates a post, it is linked to the form unless you unlink it through code. The form entry and linked post both belong to the user that created them. When you unlink the the form entry from the post, you no longer have the ability to edit the post through the form.

User roles are handled completely by WordPress and are found in the wp_user_metas table. User roles are linked to the owner of record for both the form entry and linked post.

To have a different user role, you have to change the owner of record for both the form entry and post. Editing a form entry does not change the owner of record.

In WordPress, the author role has a higher level of authority than a subscriber role. So you have a higher level of authority creating an entry and a lower level publishing it, which is the opposite of how WordPress works.

Are you trying to ensure that only authorized users can create form entries, but once they are created, the associated posts are available for all to see? If not, what exactly are you trying to accomplish? There may be alternatives.

I have found a workaround to this for anyone who might need help with a similar use-case.

The users creating the form above have a previously created (profile) form with a post status field.

With my use-case, it worked for me to populate the Post Status field in the second form with the value of the post status field from the profile form which they first created. I achieved this by using the following shortcode:

[frm-field-value field_id=x user_id=current show=value]

with 'x' being the ID of the post status field from the first profile form (in my case). I placed this shortcode in the Dynamic Default Value section in the field settings of the Post Status field in the second form.

Cheers.

Discussion closed.