I need to theme a node content type as a form. For example, the node has fields:
field_body = a question, e.g. "What is your favourite color?"
field_answers = field collection ------------------> these will become radio buttons
field_content = an answer, e.g. "Blue"
field_internal = internal value for the radio button
field_points = how many points for this answer ---------> this will become an html attribute
field_additional = "some additional info about this answer ---------> this will become an html attribute
and so on, each question has 3 answers to choose. This is a questionnaire, the editor adds questionnaires dynamically. I don't want Webform module in this case.
So far I've written a mymodule_theme()
function (in a custom module) for the whole node with answers, and themed it as a form using raw html output, something like this:
$output = '<form>';
... loop
$output .= '<input type="radio" name="myquestion" value="' . $field_internal_value . '"> . $field_content_value .'<br>'
...
But Drupal has form API. I could as well build a $form
render array in mymodule_theme()
, instead of raw html and then use:
$output = drupal_render($form)
The question:
in the above example, is there any real advantage of building a form array and rendering it using drupal_render
, instead of building the output from raw html as shown? For example, advantage with using ajax later, or submitting, or validating "the Drupal way" etc. (I think not because form API applies only to static forms which are defined in a module, but I'm not sure).