function tripal_mviews_form_validate

2.x tripal_core.mviews.inc tripal_mviews_form_validate($form, &$form_state)
3.x tripal_chado.mviews.inc tripal_mviews_form_validate($form, &$form_state)
1.x mviews.inc tripal_mviews_form_validate($form, &$form_state)

Validate the Create/Edit Materialized View Form Implements hook_form_validate().

Related topics

File

tripal_core/includes/mviews.inc, line 348
Contains functions for viewing and editing of Materialized Views on a Tripal website.

Code

function tripal_mviews_form_validate($form, &$form_state) {
  $action = $form_state['values']['action'];
  $mview_id = $form_state['values']['mview_id'];
  $name = $form_state['values']['name'];
  $mv_table = $form_state['values']['mv_table'];
  $mv_specs = $form_state['values']['mv_specs'];
  $indexed = $form_state['values']['indexed'];
  $query = $form_state['values']['mvquery'];
  $special_index = $form_state['values']['special_index'];
  $comment = $form_state['values']['comment'];
  $schema = $form_state['values']['schema'];

  if ($schema and ($mv_table or $mv_specs or $indexed or $special_index)) {
    form_set_error($form_state['values']['schema'], 
    t('You can create an MView using the Drupal Schema API method or the ' .
      'traditional method but not both.'));
  }
  if (!$schema) {
    if (!$mv_specs) {
      form_set_error($form_state['values']['mv_specs'], 
      t('The Table Definition field is required.'));
    }
    if (!$mv_table) {
      form_set_error($form_state['values']['mv_table'], 
      t('The Table Name field is required.'));
    }
  }

  // make sure the array is valid
  if ($schema) {
    $success = eval("\$schema_array = $schema;");
    if ($success === FALSE) {
      $error = error_get_last();
      form_set_error($form_state['values']['schema'], 
      t("The schema array is improperly formatted. Parse Error : " . $error["message"]));
    }
    if (!array_key_exists('table', $schema_array)) {
      form_set_error($form_state['values']['schema'], 
      t("The schema array must have key named 'table'"));
    }

    // TODO: add in more validation checks of the array to help the user
  }
}