1 database_example.module database_example_form_update_callback($form, $form_state)

AJAX callback handler for the pid select.

When the pid changes, populates the defaults from the database in the form.

Related topics

File

modules/examples/database_example/database_example.module, line 485
Hook implementations for the Database Example module.

Code

function database_example_form_update_callback($form, $form_state) {
  $entry = $form_state['entries'][$form_state['values']['pid']];
  // Setting the #value of items is the only way I was able to figure out to get
  // replaced defaults on these items. #default_value will not do it and should
  // not.
  foreach (array('name', 'surname', 'age') as $item) {
    $form[$item]['#value'] = $entry->$item;
  }
  return $form;
}