geocoder.admin.inc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @file
  4. * Settings form.
  5. */
  6. /**
  7. * Module settings page.
  8. */
  9. function geocoder_admin_settings($form, &$form_state) {
  10. $geocoder_settings= variable_get("geocoder_settings", array());
  11. $form['geocoder_apikey_yahoo'] = array(
  12. '#type' => 'textfield',
  13. '#title' => t('Yahoo PlaceFinder API Key'),
  14. '#description' => t('You can obtain a Yahoo PlaceFinder consumer key at') . ' ' . 'http://developer.yahoo.com/geo/placefinder/',
  15. '#default_value' => empty($geocoder_settings['geocoder_apikey_yahoo']) ? '' : $geocoder_settings['geocoder_apikey_yahoo'],
  16. '#required' => FALSE,
  17. );
  18. $form['geocoder_apikey_yandex'] = array(
  19. '#type' => 'textfield',
  20. '#title' => t('Yandex Maps API Key'),
  21. '#description' => t('You can obtain a Yandex API Key at ') . 'http://api.yandex.ru/maps/getkey.xml',
  22. '#default_value' => empty($geocoder_settings['geocoder_apikey_yandex']) ? '' : $geocoder_settings['geocoder_apikey_yandex'],
  23. '#required' => FALSE,
  24. );
  25. $form['#submit'][] = 'geocoder_admin_settings_submit';
  26. return system_settings_form($form);
  27. }
  28. function geocoder_admin_settings_validate($form_id, $form_values) {
  29. if (!empty($form_values['values']['geocoder_apikey_yahoo']) && preg_match("/[^A-Za-z0-9\\-]/", trim($form_values['values']['geocoder_apikey_yahoo']))) {
  30. form_set_error('geocoder_apikey_yahoo', t('Yahoo API keys are alpha numeric and dashes only.'));
  31. }
  32. }
  33. function geocoder_admin_settings_submit($form, &$form_state) {
  34. $geocoder_settings= variable_get("geocoder_settings", array());
  35. $geocoder_settings['geocoder_apikey_yahoo'] = trim($form_state['values']['geocoder_apikey_yahoo']);
  36. $geocoder_settings['geocoder_apikey_yandex'] = trim($form_state['values']['geocoder_apikey_yandex']);
  37. variable_set("geocoder_settings", $geocoder_settings);
  38. }