You can but you shouldn’t: required Custom Fields

Here’s a pro tip for working with custom fields in CiviCRM:

When CiviCRM asks you if you want to make a custom field “required,” just say no.

You could say yes, but if you value your sanity, you should simply never do this.

Doing so can create some surprising troubles. Not that it will completely break your CRM, but it can cause unexpected errors in unexpected places.

Today i solved such a problem for a client who was in a fair bit of pain over it (and under significant time pressure, too).

For them, the problem showed up as a validation error on a contribution page. No matter what they tried, the contribution form would fail with a cryptic error message, "Payment Processor Error message :DB Error: unknown error".

The problem? A required field on the Individual contact record — a field that was not even available in the form being submitted. (Think about it: if the field isn’t in the form, how could it have a value? And if it’s required to have a value, how could the form be submitted successfully?)

They’re trying to get this launched as part of a scheduled campaign, and as holiday schedules play havoc with everyone’s availability, they were worried this was going to delay things. Not good.

I sorted them out, and they’re happy. But I think a few of them gained several gray hairs over it.

“But Allen, what if I need to require the field in a form?”

That’s completely reasonable, and doesn’t make a problem. If you’re using Profiles, it’s fine to mark the field “required” in the profile. Same goes for FormBuilder: require away!

But setting the custom field itself to required, that’s just thumbing your nose at the gods of chaos.

And they will find you, believe me.

All the best,
A.

Previous
Previous

“I didn’t edit that”

Next
Next

♬“It’s the most stressful time of the year” ♬