You are here

function fillpdf_form_import_form_submit in FillPDF 6

Same name and namespace in other branches
  1. 7.2 fillpdf.admin.inc \fillpdf_form_import_form_submit()
  2. 7 fillpdf.admin.inc \fillpdf_form_import_form_submit()

File

./fillpdf.admin.inc, line 535
Allows mappings of PDFs to site content

Code

function fillpdf_form_import_form_submit($form, &$form_state) {
  $pdf_form = new stdClass();
  $pdf_form->fid = $form_state['values']['fid'];
  $mappings = $form_state['values']['mappings'];
  $fields = fillpdf_get_fields($pdf_form->fid);
  $field_keys = array_keys($fields);

  // Process the mappings
  foreach ($mappings as $pdf_key => $field_settings) {
    if (in_array($pdf_key, $field_keys)) {
      $field_settings = (object) $field_settings;
      $field_settings->pdf_key = $pdf_key;
      fillpdf_update_field($pdf_form, $field_settings, $pdf_key);
    }
    else {
      drupal_set_message(t('Your code contained field mappings for the PDF field key <em>@pdf_key</em>, but it does not exist on this form. Therefore, it was ignored.', array(
        '@pdf_key' => $pdf_key,
      )), 'warning');
    }
  }
  drupal_set_message(t('Successfully imported matching PDF field keys. If any field mappings failed to import, they are listed above.'));
  $form_state['redirect'] = "admin/content/fillpdf/{$pdf_form->fid}";
}