I have added two fields in to my custom content type using "Add existing field".

For specific URL, I need to set these two fields as Required.

So I have altered my form and set required condition. After setting it, I have printed the form using devel, these fields are having required settings.

$form['field_name']['und']['#required'] = TRUE;
$form['field_email']['und']['#required'] = 1;

But required condition is not applied.

enter image description here enter image description here

That is, I could not see red color required indication as well as its not working in the form submit.



$form['field_email']['und']['0']['value']['#required'] = TRUE;

and if not work then try

$form['field_email']['und']['0']['#required'] = TRUE;
| improve this answer | |
  • @kalidasan your welcome :). – Yuseferi Dec 23 '13 at 16:03
  • @kalidasan please if you get your answer mark the answer as correct – Yuseferi Dec 23 '13 at 16:05
  • Thanks for the ['value'] tip. That's what was missing for me. – mcaleaa Jan 27 '15 at 10:25
  • @mcaleaa your welcome, it get me good sense that my answers help others in future :) – Yuseferi Jan 27 '15 at 10:30

I ended up needing an additional value set to make this work and thoguht others might benefit from knowing so:

$form['profile_personal_information']['field_company'][LANGUAGE_NONE]['#required'] = 1;
$form['profile_personal_information']['field_company'][LANGUAGE_NONE][0]['#required'] = TRUE;
$form['profile_personal_information']['field_company'][LANGUAGE_NONE][0]['value']['#required'] = TRUE;
| improve this answer | |

You can use Field Validation module:

This module adds an extra tab to each field instance, allowing you to specify validation rules for your field instances.

Or use hook_field_validate in you custom module.

| improve this answer | |
  • Is this module need for this small fix? – kalidasan Dec 17 '15 at 10:42

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.