You are here

function form_builder_preview_prepare in Form Builder 6

Before editing a form, modify it slightly to add functionality used in the preview and disable use of the actual form fields in any way.

Return value

A list of all element_ids currently used within this form.

2 calls to form_builder_preview_prepare()
form_builder_preview in includes/form_builder.admin.inc
Form. Given a form array, present it for editing in a preview.
form_builder_webform_save_node in modules/webform/form_builder_webform.module
Save the current Form Builder interface changes for a webform node.

File

includes/form_builder.admin.inc, line 590
form_builder.admin.inc Administrative interface for editing forms.

Code

function form_builder_preview_prepare(&$form, $form_type, $form_id, $parent_id = FORM_BUILDER_ROOT) {
  $element_ids = array();
  foreach (element_children($form) as $key) {

    // Keep record of the current parent ID.
    $previous_parent_id = $parent_id;
    if (isset($form[$key]['#form_builder']['element_id'])) {
      $element_ids[] = $form[$key]['#form_builder']['element_id'];
      $form[$key]['#pre_render'][] = 'form_builder_pre_render';
      $form[$key]['#form_builder']['form_type'] = $form_type;
      $form[$key]['#form_builder']['form_id'] = $form_id;
      $form[$key]['#form_builder']['parent_id'] = $parent_id;
      $parent_id = $form[$key]['#form_builder']['element_id'];
    }

    // Search within this element for further form elements.
    $additional_ids = form_builder_preview_prepare($form[$key], $form_type, $form_id, $parent_id);
    $element_ids = array_merge($element_ids, $additional_ids);
    $parent_id = $previous_parent_id;
  }
  return $element_ids;
}