Undefined index: und I have created a custom profile field called "field_protection". I am using the following code to reference that field but am getting error:

Notice: Undefined index: und 

$is_protected = 0;
   $is_protected  = (int)$act-&gt;field_protection['und']['0']['value'];
    if ($is_protected == 1) {
      form_set_error('from', t("Protected !!!"));
      return;
    }
I like to use EntityAPI module for working with fields. You don't need to worry about some key exists or not. here is an example:

$entityWrapper = entity_metadata_wrapper('ENTITY_TYPE (eg. node, user..)', ENTITY_KEY_OR_ENTITY);

$protectionFieldValue = $entityWrapper-&gt;field_protection-&gt;value();

if (null != $protectionFieldValue /* put your condition */) {
  form_set_error('from', t("Protected !!!"));
  return;
}


or here is a way without an EntityAPI:

if (isset($act-&gt;field_protection['und']) &amp;&amp; ($is_protected  = (int)$act-&gt;field_protection['und']['0']['value'])) {
    if ($is_protected == 1) {
      form_set_error('from', t("Protected !!!"));
      return;
    }
}