Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Using Drupal Existing Fields To Custom Form

Parent Feed: 

Below is code to use field attached form hook.

/** * Implements hook_form() */ function hook_form($form, &$form_state) { $entity_type = 'node'; $entity_info = new stdClass(); $entity_info->type = 'test'; $field = 'field_test_image'; //to attach test content type's field to the form field_attach_form($entity_type, $entity_info, $form, $form_state, NULL, array('field_name' => $field)); $form['submit'][] = 'hook_custom_submit'; return $form; } /** * Implements hook_submit() */ function hook_custom_submit($form, $form_state) { $form_values = $form_state['values']; $node = new stdClass(); $node->type = 'test'; $node->field_test_image = $form_values[‘field_test_image’]; node_save($node); }

Author: 
Original Post: