Strange problem when creatng Drupal 7 Module form_submit and db_update

Today we were creating a new custom module in Drupal and we had a form we had created and a submit handler. In the submit handler we had a db_update to update the row in the database. For ages we couldn’t find out why it wasn’t working until we noticed we’d set the update variables using

$form_state['values']['name']

This is wrong. This stores the values of the form fields as they were when the form was generated. To get the values of the fields as they were submitted, you need:

$form_state['input']['name']

One of those things that takes hours to spot! ARRRGGHH!!!

About the Author

I'm a web developer based in the East Midlands, UK and if I keep up the current rate, I might have developed 3 million sites by the time I retire