You are here

function biblio_form in Bibliography Module 5

Same name and namespace in other branches
  1. 6.2 biblio.module \biblio_form()
  2. 6 biblio.module \biblio_form()
  3. 7 biblio.module \biblio_form()
  4. 7.2 biblio.module \biblio_form()

Implementation of hook_form().

Create the form for collecting the information specific to this node type. This hook requires us to return some HTML that will be later placed inside the form.

File

./biblio.module, line 1634

Code

function biblio_form(&$node, &$param) {
  global $form_values;
  $output = '';
  $param['options'] = array(
    "enctype" => "multipart/form-data",
  );

  //$form['#pre_render'] = array('biblio_pre_render');
  $result = db_query('SELECT t.* FROM {biblio_types} as t WHERE tid > -2 AND visible = 1');
  while ($option = db_fetch_object($result)) {
    $options["{$option->tid}"] = $option->name;
  }
  $form['biblio_type'] = array(
    '#type' => 'select',
    '#title' => t('Publication Type'),
    '#default_value' => $node->biblio_type,
    '#options' => $options,
    '#description' => null,
    '#weight' => -5,
    '#attributes' => array(
      'onchange' => 'document.getElementById(\'node-form\').submit()',
    ),
    '#multiple' => false,
    '#required' => true,
  );
  $form['title'] = array(
    // this will be set to textfield type in pre_render once the pub type is set.
    '#type' => 'value',
    '#title' => t('Title'),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#size' => 60,
    '#maxlength' => 255,
    '#weight' => -4,
  );

  // Build the field array used to make the form
  $result = db_query('SELECT * FROM {biblio_fields} as b  ORDER BY b.weight ASC');
  while ($row = db_fetch_array($result)) {

    // if ($row['common']) {
    $fields[$row['fid']] = $row;

    // }
  }

  // Now set all the fields to "value" type so the will not be visible, and
  // then in biblio_pre_render the correct type will be set.
  foreach ($fields as $key => $fld) {
    $form[$fld['name']] = array(
      '#default_value' => $node->{$fld}['name'],
      '#type' => 'value',
      '#title' => check_plain($fld['title']),
      '#size' => $fld['size'],
      '#required' => $fld['required'],
      '#maxlength' => $fld['maxsize'],
      '#weight' => $fld['weight'] / 10,
      '#autocomplete_path' => $fld['autocomplete'] ? 'biblio/autocomplete/' . $fld['name'] : '',
      '#description' => check_plain($fld['hint']),
    );
  }

  /*   $form['authors1'] = array('#type' => 'fieldset',
                                '#title' => t('First Authors'),
                                '#collapsible' => TRUE,
                                '#collapsed' => TRUE,
                                '#weight' => 0);
      $form['authors1']['author1_lastname'] = array(
            '#default_value' => $node->$fld['name'],
            '#type' => 'textfield',
            '#title' => t('lastname'),
            '#size' => 20,
            '#required' => 1,
            '#maxlength' => 75,
            '#weight' => 1,
            '#description' => ''
          );

      $form['authors2'] = array('#type' => 'value',
                                '#title' => t('More Authors...'),
                                '#collapsible' => TRUE,
                                '#collapsed' => TRUE,
                                '#weight' => 0);
    */
  if (variable_get('biblio_input_full_text', 1)) {
    $form['body'] = array(
      '#type' => 'value',
      '#title' => t('Full Text'),
      '#default_value' => $node->body,
      '#rows' => 10,
      '#required' => FALSE,
      '#description' => t('You may enter a full text or HTML version of the publication here.'),
      '#weight' => 19,
    );
    $form['format'] = filter_form($node->format, 20);
  }
  return $form;
}