1

I want to make it so that all new contacts must have a contact type. I have found where the contact type is in the templates, and have managed to add the wee * besides it, but I am struggling to find what tag or code I need to add to make it be an actual mandatory field. Is there some way of doing this?

3

Welcome to SE, You can set contact type mandatory by using hook_civicrm_buildForm something like below

function extension_civicrm_buildForm($formName, &$form) {
  if ('CRM_Contact_Form_Contact' == $formName
    && !($form->getVar('_action') & CRM_Core_Action::DELETE)
  ) {
    $form->addRule('contact_sub_type',  ts('This field is required.'), 'required');
  }
}

HTH

Pradeep

  • <?php function civicrm_hooks_civicrm_buildForm($formName, &$form) { if ($formName == 'CRM_Contact_Form_Edit_Individual') { $form->addRule('contact_sub_type', ts('This field is required.'), 'required'); } } is what i have so far but I cant get it to work :( any ideas? – user6861 Feb 15 at 16:23
  • I have managed to set up the hook in drupal etc, and I did see my hook on the page (i forgot the <?php initially) – user6861 Feb 15 at 16:28
  • Is it working or not? – Pradeep Nayak Feb 15 at 16:29
  • Its not working - I have successfully set the hooks up but the hook I have written does not work. – user6861 Feb 15 at 16:31
  • What is the module or extension name where you have added above code? – Pradeep Nayak Feb 15 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.