drupaldrupal-7drupal-modulesform-api

Drupal 7 - Form API Custom Module


I have a form that calculates two values, form works perfectly, however i'm having some problems working out how I can calculate the two values and return the answer as rendered HTML so I can style it all nice and pretty for the user to see.

All help will much appreciated. Thanks.


Solution

  • In a Drupal form there are three types of callback that are normally necessary to create a form:

    Of those functions, the one that outputs the result of the calculation done on the values submitted from the users is the last one. Normally, the form submission handler saves the data in the database, and show a message to the users through drupal_set_message(), but it could also simply show the result of the operations done on the entered data.

    Since Drupal 7, the output of a form submission handler, as well as the output produced from a menu callback, can be a rendering array, and not a string. A rendering array has the pro of being easily altered from third-party modules through hook_page_build(), or hook_page_alter().

    node_view() is an example of menu callback that returns a rendering array, and not a string.