Skip Navigation

[Resolved] Make post field required based on condition

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.

Our next available supporter will start replying to tickets in about 0.66 hours from now. Thank you for your understanding.

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)

This topic contains 6 replies, has 2 voices.

Last updated by sofiaM 1 year, 11 months ago.

Assisted by: Shane.

Author
Posts
#2362669

Hello,
I would like to know if it's possible to make a post field required based on a condition. For example if the users has selected that a "strategy" is of type "smart" from a radio button then the start and end date of the strategy should be required otherwise not.

Thanks

#2362803

Shane
Supporter

Languages: English (English )

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

Hi Sofia,

Thank you for getting in touch.

In order to understand the context of the useage can you let me know if you're populating the fields on the backend or on the frontend ? Meaning are you using our Toolset forms plugin to create the posts?

Thanks,
Shane

#2364021

Hello Shane,

I am populating the fields on the backend.

#2364521

Shane
Supporter

Languages: English (English )

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

Hi Sofia,

What you can do is to add a conditional display to the required field.

You can make the field required in the custom field settings but add a conditional to the field to only show up when a particular value is selected from another custom field.

Here is our documentation on this exact functionality.
https://toolset.com/course-lesson/conditionally-display-custom-fields-in-wordpress-backend/

Please let me know if this helps.
Thanks,
Shane

#2364567

I thought of that, but I want to always show the field and change if it is required or not based on a previous answer.

#2364669

Shane
Supporter

Languages: English (English )

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

Hi Sofia,

In a case like this then you will need to use custom code to achieve. Unfortunately the code required to make this field required based on the conditions defined would be out of the scope of our support forum since we don't have any validation hooks that would apply to the backend.

On the frontend this would be something that would be possible to do with our Forms validation Hook but on the backend it would require the use of the wordpress default API functions to craft a solution.

Thanks,
Shane

#2364955

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.