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.'));
}
}
Comments
Hi, in function
Hi,
in function "marli_scores", between $form['#theme'] = 'marli_scores'; and "return $form" put "$form['#tree'] = TRUE;" And the function "marli_admin_submit" shouldn't be named "marli_scores_submit"? Or do you change in another place the $form['base'] value?
Vasi.
Below is the rest of the code
Below is the rest of the code omitted, the process basically goes:
View form, database collects current scores, I edit values, submit edited form, update database, show changes
sadly im lacking on the latter due to being abit green to Form Api
this whole issue is more complex because im collecting around 500 rows.
Im finding with abit of
Im finding with abit of tweaking the values being returned are always 0. regardless of what i enter into the fields.
Have you put put
Have you put put $form['#TREE'] = TRUE, as I said in the previous comment?
yes still outputting 0
yes still outputting 0