1

I am trying to make field(s) of Entity Form as required. The field(s) that I want to make required works fine when its one field but when I mention that a field(s) can accept unlimited values the required field(s) doesn't work. In other words only first field becomes required and not all other fields which user adds after pressing "Add another Item" button.

I am trying to hook_form_alter() but still I am not able to achieve where all additional fields become required when user presses add new item button. Below is the code that I wrote.

function mymodule_form_alter(&$form, &$form_state, $form_id) {

print_r($form_id);

if ($form_id == 'my_form_name') {

drupal_set_message('<pre>' . print_r($form, true) . '</pre>');


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

}

}

Your Answer

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

Browse other questions tagged or ask your own question.