How to compare before and after state in whatever_submit($form, &$form_state) In a custom module, I have a form allowing some Create/Update/Delete data in a specific table of the database.
In the submit part of the code, I'd like to compare 'before' state (what was displayed to the user) to 'after' state (what he has actually entered) in order to properly update the database: create what has been added, update what has been changed and delete what has been removed.
How can I do that?
By the way, the site is running Drupal 6.37.
First of all: You should migrate to Drupal 7 or 8. Drupal 6 is no longer supported as of Feb 24th, 2016.
If migration is not possible, perform security updates. The latest version of Drupal 6 is 6.38 released on 24 February 2016. Have you also heard about the Drupal 6 LTS initiative? I highly recommend reading the details https://www.drupal.org/project/d6lts, https://github.com/d6lts/drupal.

Answering your question, the simplest thing would be to pass the object with the data in the form:

$form['my_object'] = array(
  '#value' =&gt; $my_object,
  '#type' =&gt; 'value',
);

$form['some_field'] = array(
  '#default_value' =&gt; $my_object-&gt;some_field,
  '#type' =&gt; 'textfield',
);


Then in the submit handler you can compare values:

if ($form_state['values']['my_object']-&gt;some_field != $form_state['values']['some_field']) {
  // Value of some_field has changed!
}