1 tabledrag_example_parent_form.inc tabledrag_example_parent_form_submit($form, &$form_state)

Submit callback for the tabledrag_example_parent_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_parent_form.inc, line 264
Example demonstrating a parent/child tabledrag form

Code

function tabledrag_example_parent_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, pid = :pid WHERE id = :id", 
    array(':weight' => $item['weight'], ':pid' => $item['pid'], ':id' => $id)
    );
  }
}