Fix for bug in _form_builder_handle_input_element() function in form.inc ..

  1. <?php # vim: set filetype=php expandtab tabstop=2 shiftwidth=2 autoindent smartindent:
  2.  
  3. function user_queue_member_admin($form, $form_state = NULL) {
  4.   if (module_exists("profile")) {
  5.     $default_value = FALSE;
  6.     if ($field = _user_queue_member_get_profile_field()) {
  7.       $default_value = $field->name ." [". $field->fid ."]";
  8.     }
  9.     $form["profile_field"] = array(
  10.       "#type" => "textfield"
  11.       , "#title" => t("Phone number field")
  12.       , "#autocomplete_path" => "admin/user/user_queue_member/autocomplete"
  13.       , "#required" => FALSE
  14.       , "#default_value" => $default_value
  15.     );
  16.   }
  17.   else {
  18.     $form["profile_field"] = array(
  19.       "#title" => t("Phone number field")
  20.       , "#value" => t("Enable profile module to send calls to user phone number.")
  21.     );
  22.   }
  23.   $form["save"] = array(
  24.     "#type" => "submit"
  25.     , "#value" => "Save"
  26.   );
  27.   return $form;
  28. }
  29.  
  30. function user_queue_member_admin_validate($form, &$form_state) {
  31.   die();
  32.   if ($form_state["values"]["profile_field"]) {
  33.     /* parse the profile field */
  34.     if (!preg_match("^.*\[([0-9]+)\]$", $form_state["profile_field"], $matches)) {
  35.       form_error($form["profile_field"], "Profile field could not be identified, you can keep it blank if you do not want to use phone number.");
  36.       return;
  37.     }
  38.     /* see if the fid exists */
  39.     if (!$field = db_fetch_object(db_query('SELECT f.name, f.fid FROM {profile_fields} f WHERE f.fid = %d', $matches[1]))) {
  40.       form_error($form["profile_field"], "Profile field does not exist, you can keep it blank if you do not want to use phone number.");
  41.       return;
  42.     }
  43.     $form_state["fid"] = $field->fid;
  44.   }
  45. }
  46.  
  47. function user_queue_member_admin_submit($form, &$form_state) {
  48.   die();
  49.   if ($form_submit["fid"]) {
  50.       variable_set(USER_QUEUE_MEMBER_PHONE_NUMBER, $form_submit["fid"]);
  51.   }
  52. }
  53.  
  54. function user_queue_member_admin_autocomplete($string) {
  55.   $matches = array();
  56.   $result = db_query_range("SELECT f.name, f.fid FROM {profile_fields} AS f WHERE LOWER(f.name) LIKE LOWER('%s%%')", $string, 0, 10);
  57.   while ($data = db_fetch_object($result)) {
  58.     $matches[$data->name ." [". $data->fid ."]"] = check_plain($data->name);
  59.   }
  60.   drupal_json($matches);
  61. }