Hi,

The TableField module is working great on my custom content type. I am trying to add this field to a custom form I am building. I tried the following codes but they are not producing any fields. How can I use the tablefield type on a custom form?

	$form['custom_field_test'] = array(
		"#type" => "tablefield",
		"#title" => t("Testing...")
	);

Thanks,
Roosevelt

Comments

vitalie’s picture

Tablefield is not available as a form element, though it would have been nice to have it. (The dev D8 branch has it actually).

For now all you can do is to try to use the field widget form. But for this you have to have a content type that uses the tablefield. So code like this:

  $form_state = array();
  // This is necessary for field_default_form() not to yell at us.
  $form['#parents'] = array();

  $lang = LANGUAGE_NONE;
  $field_name = 'field_your_tablefield_field';

  $field = field_info_field($field_name);
  $instance = field_info_instance('node', $field_name, 'your_content_type');
  $form += field_default_form('node', NULL, $field, $instance, $lang, NULL, $form, $form_state);
lolandese’s picture

Priority: Major » Normal
Status: Active » Fixed

This seems to be answered. Feel free to reopen if still help on this issue is needed using the latest version.

lolandese’s picture

Have also a look at the Table Element module.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.