function tabledrag_example_parent_form_submit

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

tabledrag_example/tabledrag_example_parent_form.inc, line 264

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,
        ));
    }
}