Restrict "add more" button to add new fieldset after adding 5 fieldsets I have taken a field of type field collection in my user-profile-form and its cardinality is set to unlimited as I wanted to have "add more" button for the users. I want to restrict the addition of fieldset to five numbers.

If I change the number of fields to be displayed to 5 from edit, it renders all the five fieldsets altogether which I do not want.

I tried overriding field_multiple_value_form() in my template.php file but did not succeeded. Please suggest some ideas to achieve this.
Thanks In advance.
This can be achieved using css. First of all write hook_form_alter() on your custom module. and your code should be like this..


function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'your_form_id') {
    if (isset($form['your_field']['und']['#max_delta']) && $form['your_field']['und']['#max_delta'] == 4) {
      $form['your_field']['und']['add_more']['#prefix'] = '';
      $form['your_field']['und']['add_more']['#suffix'] = '';    
    }
  }
}



Where $form['your_field'] is your field collection field machine name. You can write your custom css on #prefix and #suffix and set it to display none.