You are here

function dbtng_example_form_update_callback in Examples for Developers 7

AJAX callback handler for the pid select.

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

Related topics

1 string reference to 'dbtng_example_form_update_callback'
dbtng_example_form_update in dbtng_example/dbtng_example.module
Sample UI to update a record.

File

dbtng_example/dbtng_example.module, line 598
This is an example outlining how a module can make use of the new DBTNG database API in Drupal 7.

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