Choice of mandatory fields: How to in CCK

Events happening in the community are now at Drupal community events on www.drupal.org.
droople's picture

I have 2 fields called "local tele" and "non-geo telephone" for the phone field for cck

so users can enter either a 01233 or 08xx number, or even both.

Of these 2 fields I want at least one to be mandatory when creating the node

  1. so if a user doesn't enter either of the two, a "required field" error is rendered and node won't submit

  2. If a user enters "local tele" then non-geo can be ignored and vice-versa

  3. if user enters both fields, then both will appear on the node

thanks

Comments

Custom Validator

cabbiepete's picture

I had a similar thing where the user selected payment method and then depending on that some fields were mandatory. I solved the validation issue by writing a custom validator and hooking in to hook_field and hook_widget on op = 'validation'.

To make the UI look right I left the fields as not required in the form API form array and used JQuery to add the required class and span as per the theme, I did the jquery stuff in a theme method for the field.

Hope that makes sense and helps you go in a direction that works for you.

Content Construction Kit (CCK)

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: