2

I created a custom content type called 'Building Location' that contains a custom field called 'US_States'.

Is there a way I can access and include the 'US_States' field into a custom form I'm building without having to re-create it with the Form API?

I'm looking to include the same drop down list, 'US_States,' from the 'Building Location' content type in a custom form that is part of a module I'm building, ensuring the two will always have the same options available.

1 Answer 1

1

There isn't an API for attaching a single field from an entity to a form, there is one to attach all fields. field_attach_form. I wouldn't suggest you doing that do, since it can quickly become unmaintainable.

Instead I would suggest that you simply get the field options, or allowed values as they are called. That is pretty simple as well.

$info = field_info_field('field_machine_name');
$options = $info['settings']['allowed_values'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.