0

Is it possible to retrieve only parts of a form for display, that is, only certain form elements?

I am looking at the stack for building the node form, and so far the functions I've seen work with wholesale forms, in this case the node_form.

drupal_retrieve_form(): /.../http/includes/form.inc at line 752
drupal_build_form(): /.../http/includes/form.inc at line 331
drupal_get_form(): /.../http/includes/form.inc at line 123

I am interested in only retrieving (rendering) the default body field via AJAX only for a preview type of display. So far I've been successfully build and render the whole node form just using the #AJAX FAPI property and other Drupal hooks - but I was wondering if something similar was possible for just one field. Answers that point to Drupal core APIs instead of contrib modules (who may be using their own jQuery magic) are a plus.

I'm just gathering thoughts to see how I write a D7 module for this question.

  • I'm not sure your question makes sense. You cannot save "just the body" of a node without saving the whole node with the other fields. Can you clarify your business logic (what are you trying to show, where do you want it to save). – tenken Aug 21 '12 at 22:30
  • Clarified question... – amateur barista Aug 22 '12 at 14:20
1

This is how I might end up doing it:

  • When a JavaScript callback is triggered by a user editing the body field (this can be done via the #ajax property), clone current node found on form_state.
  • Create a render array for the whole node by using FAPI's drupal_build_form($form_id, $form_state).
  • Extract the body field from the render array.
  • Render the body field.
  • Return HTML to the front-end (JavaScript) so it can be placed on a preview DIV.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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