Domanda

I want to create a form inside a table and i need to have images and some text in the table. I know i can use #prefix and #suffix when creating a form but code like this:

$form['example'] = array(
  '#type' => 'textfield',
  '#title' => t('Title'),
  '#prefix' => '<table><tr><td>Some text</td><td><img some image></td>',
  '#suffix' => '</tr></table>',
);

is hard to read and debug.

So my question is can i create a form and then send it to a template file where i can set the form inside the table and add the other images and text i need to display.

This is how i want it to look: How it need to look

È stato utile?

Soluzione

You can use a dedicated theme function (not a template) to customize a form. An example is from Drupal core is the theme_menu_overview_form() function. This function is used to theme the menu_overview_form form and is registered as theme function in menu_theme().

The function build the variables used to call the table theme function (ie. theme('table', $variables));). It render the selected form element inside the rows (using drupal_render()). After renderign the table itself, the remaining form elements are appended, this include the submit button. Off course, you can also output some form element (or complete fieldsets) before the table.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top