Skip Navigation

[Resolved] Set field as require if matching with specified condition

This support ticket is created 6 years, 5 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by Nigel 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#1103271
Screen Shot 2018-09-08 at 9.29.58 PM.png

Dear Sir/Madam,

I have two custom fields "social media" and "social media account", "social media" is a selection field if customer select any one of the selections, the "social media account" is showed for entry. "social media account" is set as the required field when "social media" field is selected.

There is no error if I submit the post via CRED form but when I edit the custom post from dashboard, the "social media account" is must be filled, how can I fix this issue?

Best regards,

Kelvin

#1104344

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Kelvin

The behaviour of Toolset Forms was changed to be less restrictive (not requiring a required field if it was hidden), but Types wasn't updated with the same behaviour.

I spoke to the developers who said it should be possible to update Types to behave in the same way, and so I am filing a request for that.

In the meantime there is not much you can do other than remove the required setting for the Social Media Account field, so that it is not applied on the back end, but meaning it will also not be applied on the front end.

If you want to still make it required in the front end form, you would need to use the cred_form_validate hook to add server-side validation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

#1105343

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2018-09-11 at 08.37.32.png

Hi Kelvin

I think I misunderstood your problem, because my colleague pointed out that the behaviour is the same when editing posts in the backend as it is in front-end forms, and I just tested it now myself and that's correct: if the second field is conditionally displayed according to the value of the first field, when it is hidden the required setting is not applied.

I think your problem when editing the post in the backend is that the second field is not hidden.

Go to Toolset > Custom Fields and edit the second field and add a condition so that it is only displayed when needed based upon the value of the social media field.

In the screenshot you can see I added a condition to a field based upon the value of an "add required" field.