1 tabledrag_example_simple_form.inc tabledrag_example_simple_form_submit($form, &$form_state)

Submit callback for the tabledrag_example_simple_form form.

Updates the 'weight' column for each element in our table, taking into account that item's new order after the drag and drop actions have been performed.

Related topics

File

modules/examples/tabledrag_example/tabledrag_example_simple_form.inc, line 168
Example demonstrating a simple (i.e. 'sort' only) tabledrag form

Code

function tabledrag_example_simple_form_submit($form, &$form_state) {
  // Because the form elements were keyed with the item ids from the database,
  // we can simply iterate through the submitted values.
  foreach ($form_state['values']['example_items'] as $id => $item) {
    db_query(
    "UPDATE {tabledrag_example} SET weight = :weight WHERE id = :id", 
    array(':weight' => $item['weight'], ':id' => $id)
    );
  }
}