Issues with the entity field output Suppose, we have an entity "song", that has a required field, called "authors":



In the list of songs in the admin panel I want to output the list of all the authors in the search block:

//search form
$form['search'] = array(
  '#type' =&gt; 'fieldset',
  '#title' =&gt; t('Basic Search'),
  '#collapsible' =&gt; TRUE,
  '#collapsed' =&gt; !empty($search_term) ? FALSE : TRUE,
);

//song name
$form['search']['search_text'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Search Term'),
  '#default_value' =&gt; !empty($search_term) ? $search_term : '',
);

//authors
field_attach_form('song', null, $form['search'], $form_state, NULL, array(
                      'field_name' =&gt; 'field_authors',
                      ));

//submit button
$form['search']['search_submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Search'),
);


In the output I get this:




How can I make the checkboxes group non-required for the search form?
Why is the order of the fields broken? I added authors before the submit button, but in the output it's below the button.
If I may, you're not doing this in the most optimal way.

The best solution would be to implement hook_views_data(), and describe your custom entity's base table to Views. Then you can use Views to build your page through the UI, and all of your entity's properties and fields will be available to output as fields, filter by (exposed or not), and sort by. 

You get all of the flexibility you're used to with Views for nodes, and it's easy to write custom field/filter/sort handlers for your custom properties if they need a bit more functionality than the default.

To answer your original questions (in case you don't want to go down the Views path):


Remove the required attribute after the call to field_attach_form(), e.g. unset($form['field_foo'][LANGUAGE_NONE]['value']['#required']);
The order isn't broken, it's exactly what you've asked for. If you want the fields to appear before the search, but field_attach_form() before the definition of $form['search'].