Skip Navigation

[Resolved] Pre-select form field based on user role

This support ticket is created 4 years, 7 months 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Ian 4 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1561535

Ian

I am trying to pre select the taxonomy in a form based on the users role.

Taxonomy is Section
Terms are: Fire Department, Live & Work, Office. Recreation
User roles are: Fire Department Manager, Live and Work Manager, Office Manager, Recreation Manager

So essentially I want to pre select the section with the matching department user role

I looked at the following links for inspiration.
https://toolset.com/forums/topic/pre-fill-value-for-checkboxes-select-lists-and-radio-buttons/
https://toolset.com/forums/topic/pre-select-radio-button-in-cred-post-form-based-on-user-field/

#1561661

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ian,

Thank you for getting in touch.

Based on your situation this can be quite complex;. You want to select the values based on the user's role.

While i'm not able to write the code for you as this is out of our support forum scope. However what you will need to do is to have a point on the page where you will the user's role displayed, then from there you use Javascript to pick up the role that is displayed.

Using an If statement in the Javascript you can then switch to the different code that is being used to select the various values of the fields.

This is one way to look at it.

The other way is to completely remove these fields from your form and use php in our CRED hook to set the values when the user submits the form. This is probably the easier approach.

Thanks,
Shane

#1561797

Ian

I would use the PHP method except some users are allowed to change the section items are in.

One thing that would make things better, more foolproof, is an easy way to set form fields as required.

#1561831

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ian,

There is a way to make the taxonomy required by using our Validation hook.

What you can do is to have a look at the support resolve thread summary in the link below.

https://toolset.com/forums/topic/make-a-taxonomy-required-in-a-post-form/

This should be able to help you with this.
Thanks,
Shane

#1561929

Ian

My issue is resolved now. Thank you!