Questo codice lavora perfettamente e con grande soddisfazione lo posto! Grazie a tutti quelli che hanno dato dei consigli perchè il codice riportato altrove è simile ma proprio incompleto e inesatto. Ora potete implementare il vostro sito con delle funzionali tabelle droppabili fino a 200 record. Utilizzate lo script come volete o all'interno dei vostri moduli o create un modulo sulla base di questo codice e soprattutto, per il funzionamento create la tabella con il codice sql mostrato.
<?php
/*
CREATE TABLE dr_foo (
id serial NOT NULL,
value1 varchar(255) NOT NULL default '',
value2 varchar(255) NOT NULL default '',
weight smallint NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);
INSERT INTO dr_foo (id, value1, value2, weight) VALUES (1, 'a', 'a', 1);
INSERT INTO dr_foo (id, value1, value2, weight) VALUES (2, 'b', 'b', 2);
INSERT INTO dr_foo (id, value1, value2, weight) VALUES (3, 'c', 'c', 3);
INSERT INTO dr_foo (id, value1, value2, weight) VALUES (4, 'd', 'd', 4);
INSERT INTO dr_foo (id, value1, value2, weight) VALUES (5, 'e', 'e', 5);
*/
function example_menu() {
$items = array();
$items[example] = array(
'title' => t('Example tabledrag'),
'page callback' => 'drupal_get_form',
'page arguments' => array('example_form'),
'access arguments' => array('go example'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function example_form(&$form_state){
$form['#submit'][] = 'example_form_submit';
$result = db_query("SELECT id, value1, value2, weight FROM {foo} ORDER BY weight");
while ($row = db_fetch_object($result)){
$data = array($row->value1, $row->value2);
$form['rows'][$row->id]['data'] = array('#type' => 'value', '#value' => $data);
$form['rows'][$row->id]['weight-'.$row->id] = array(
'#type' => 'weight',
'#delta' => 200,