You are here

function _webform_render_component in Webform 6.3

Same name and namespace in other branches
  1. 7.4 webform.api.php \_webform_render_component()
  2. 7.3 webform.api.php \_webform_render_component()

Render a Webform component to be part of a form.

Parameters

$component: A Webform component array.

$value: If editing an existing submission or resuming a draft, this will contain an array of values to be shown instead of the default in the component configuration. This value will always be an array, keyed numerically for each value saved in this field.

$filter: Whether or not to filter the contents of descriptions and values when rendering the component. Values need to be unfiltered to be editable by Form Builder.

See also

_webform_client_form_add_component()

Related topics

File

./webform.api.php, line 636
Sample hooks demonstrating usage in Webform.

Code

function _webform_render_component($component, $value = NULL) {
  $form_item = array(
    '#type' => 'textfield',
    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
    '#required' => $component['mandatory'],
    '#weight' => $component['weight'],
    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],
    '#default_value' => $filter ? _webform_filter_values($component['value']) : $component['value'],
    '#prefix' => '<div class="webform-component-' . $component['type'] . '" id="webform-component-' . $component['form_key'] . '">',
    '#suffix' => '</div>',
  );
  if (isset($value)) {
    $form_item['#default_value'] = $value[0];
  }
  return $form_item;
}