Form values appear blank when submitting to the database - Drupal FormAPI

Posted by GaxZE on Stack Overflow See other posts from Stack Overflow or by GaxZE
Published on 2010-04-27T10:31:38Z Indexed on 2010/04/27 10:33 UTC
Read the original article Hit count: 284

Filed under:
|
|
|

Hello,

I have been working on this drupal form API script for past week and half. to give an insight into my problem.. the form below merely lists a host of database records which contain 5 individual scoring ranks. (mind, action, relationship, language and IT).

this code is apart of my own custom module where all values are listed from the database. the idea behind this module is to be able to edit these values on a large scale.

I am having trouble getting the values entered in the form to be passed to the variables inside of the marli_admin_submit function. the second problem is the assigning those values to their specific ID. for this purpose id like to add im merely trying to get just one score updated rather than all of them.

below is my code.

any advice appreciated.

function marli_scores(){
  $result = pager_query(db_rewrite_sql('SELECT * FROM marli WHERE value !=  " "'));

  while ($node = db_fetch_object($result)) {
    $attribute = $node->attribute;
    $field = $node->field_name;
    $item = $node->value;
    $mind = $node->mind;
    $action = $node->action;
    $relationship = $node->relationship;
    $language = $node->language;
    $it = $node->it;
    $form['field'][$node->marli_id] = array('#type' => 'markup', '#value' => $field, '#prefix' => '<b>', '#suffix' => '</b>');
    $form['title'][$node->marli_id] = array('#type' => 'markup', '#value' => $item, '#prefix' => '<b>', '#suffix' => '</b>');
    $form['mind'][$node->marli_id] =  array('#type' => 'textfield', '#maxlength' => '1', '#size' => '1', '#value' => $mind);
    $form['action'][$node->marli_id] = array('#type' => 'textfield', '#maxlength' => '1', '#size' => '1', '#value' => $action);
    $form['relationship'][$node->marli_id] =  array('#type' => 'textfield', '#maxlength' => '1', '#size' => '1', '#value' => $relationship);
    $form['language'][$node->marli_id] = array('#type' => 'textfield', '#maxlength' => '1', '#size' => '1', '#value' => $language);
    $form['it'][$node->marli_id] =  array('#type' => 'textfield', '#maxlength' => '1', '#size' => '1', '#value' => $it);

  }
  $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
  $form['save'] = array('#type' => 'submit', '#value' => t('Save'));
  $form['#theme'] = 'marli_scores';
  return $form;
}

function marli_admin_submit($form, &$form_state) {

    $marli_id = 4;
    $submit_mind = $form_state['values']['mind'][$marli_id];
    $submit_action = $form_state['values']['action'][$marli_id];
    $submit_relationship = $form_state['values']['relationship'][$marli_id];
    $submit_language = $form_state['values']['language'][$marli_id];
    $submit_it = $form_state['values']['it'][$marli_id];

    $sql_query = "UPDATE  {marli} SET mind =  %d, action =  %d, relationship = %d, language =  %d, it =  %d WHERE  marli_id = %d";


  if ($success = db_query($sql_query, $submit_mind, $submit_action, $submit_relationship, $submit_language, $submit_it)) {

    drupal_set_message(t(' Values have been saved.'));
  }
  else {
    drupal_set_message(t('There was an error saving your data. Please try again.'));
  }

}

© Stack Overflow or respective owner

Related posts about drupal

Related posts about formapi