You are here

function tablefield_field_widget_form_validate in TableField 7.3

Form validation callback.

If the POST request exceeds the server's limit of max_input_vars, the tablefield values that were computed by a CSV import will be directly get set by the CSV table, bypassing the form submission step, and also any changes that the user made on browser.

1 string reference to 'tablefield_field_widget_form_validate'
tablefield_field_widget_form in ./tablefield.module
Implements hook_field_widget_form().

File

./tablefield.module, line 1724
Provides a set of fields that can be used to store tabular data with a node.

Code

function tablefield_field_widget_form_validate(&$form, &$form_state, &$element) {
  if (tablefield_post_exceeds_max_input_vars()) {

    // Check if the values have been imported from a CSV file. If so, original
    // values still exist in $form_state['_tablefield_imported_values'].
    $values_from_csv = FALSE;
    if (isset($form_state['_tablefield_imported_values'])) {
      $values_from_csv = $form_state['_tablefield_imported_values'];
    }
    if ($values_from_csv) {

      // Each key is one of the fields multiple values.
      $elements = array_keys($values_from_csv);
      foreach ($elements as $key) {
        $table_values = $values_from_csv[$key];

        // Reconstruct in the same form as the array is passed in $form_state.
        $table_values_format = array();
        $i_row = 0;
        foreach ($table_values as $row) {
          $i_col = 0;
          foreach ($row as $cell) {
            $table_values_format['cell_' . $i_row . '_' . $i_col] = $cell;
            $i_col++;
          }
          $i_row++;
        }
        $keys = explode('--', $key);
        tablefield_replace_csv_values($form_state['values'], $keys, $table_values_format);
        $message_warning = t('This table is too large to be safely edited. The original CSV values are stored. Please import a new CSV file to make changes to this table.');
        drupal_set_message($message_warning, 'warning');
      }
    }
    else {
      $message_error = t('This table is too large to be safely edited. To assure that no data is lost, please import a new CSV file to make changes to this table.');
      drupal_set_message($message_error, 'error');
    }
  }
}