1 dbtng_example.module dbtng_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/dbtng_example/dbtng_example.module, line 514
This is an example outlining how a module can make use of the DBTNG database API in Backdrop.

Code

function dbtng_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 shouldn't.
  foreach (array('name', 'surname', 'age') as $item) {
    $form[$item]['#value'] = $entry->$item;
  }
  return $form;
}