How do I attach some entity fields (or widgets?) to a form? I am providing a form to a user to create a product.  I want to provide a few fields from a product type, along with some normal Form API input.  Example, I only want them to specify the price and SKU.  I want the submit handler to take care of creating the title name and any other fields.  In this case, a product lives as product entities and as product display nodes.  I want to present my user a single form to create and manage products.

I looks like I should be able to do this with the Field API, but I just see how to attached all fields from an entity.  I just want to attach a few.

Am I able to do this with the Field API?

EDIT TO ADD MORE INFO:

For example, when a user creates a new product, they will enter a 6 digit SKU.  Each product will have that SKU, with another 3 digits appended, specifying a category.  I want the user to simply enter the base SKU, like ABCDEF, select category Y and Z, and the submit handler creates the products with the correct SKUs, like ABCDEF-0001, ABCDEF-0002, and creates the node display.  There are also specific fields of the product type, so I need the user to populate the fields for these products, using the WYSIWYG filter they would otherwise use on the product create form.
I think you can certainly use field_attach_form. Take a look at the $options argument that is explained in more detail in the _field_invoke documentation. For more information you can also have a look at this issue: https://drupal.org/node/1825844

You can include any field of any bundle into any form using this approach:

field_attach_form('node', $entity, $form, $form_state, NULL, array(
  'field_name' =&gt; 'field_sku',
));


When I last used this approach I remember having passed a copy of the original form into field_attach_form() in order to prevent my original form from being modified to much. Then I have copied only field element into my original form:

$form_tmp = $form;
field_attach_form('node', $entity, $form_tmp, $form_state, NULL, array(
  'field_name' =&gt; 'field_sku'
));
$form['field_sku'] = $form_tmp['field_sku'];


Just look at the mentioned functions to see what they do. I'm not sure if this last part is needed.

And one more link to explore:


https://api.drupal.org/comment/49363#comment-49363