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. /*
  4.  
  5. Error: Fatal error: Cannot use string offset as an array in /data/projects/voip_support/trunk/control_interface/includes/form.inc on line 965
  6.  
  7. When it occur: when I submit user_queue_member_admin form.
  8.  
  9. */
  10.  
  11. function user_queue_member_admin($form, $form_state = NULL) {
  12.   if (module_exists('profile')) {
  13.     $default_value = FALSE;
  14.     if ($field = _user_queue_member_get_profile_field()) {
  15.       $default_value = $field->name .' ['. $field->fid .']';
  16.     }
  17.     $form['profile_field'] = array(
  18.       '#type' => 'textfield',
  19.       '#title' => t('Phone number field'),
  20.       '#autocomplete_path' => 'admin/user/user_queue_member/autocomplete',
  21.       '#required' => FALSE,
  22.       '#default_value' => $default_value,
  23.     );
  24.   }
  25.   else {
  26.     $form['profile_field'] = array(
  27.       '#type' => 'markup',
  28.       '#title' => t('Phone number field'),
  29.       '#value' => "<div>".t('Enable profile module to send calls to user phone number.')."</div>",
  30.     );
  31.   }
  32.   $form['save'] = array(
  33.     '#type' => 'submit',
  34.     '#value' => 'Save',
  35.   );
  36.   return $form;
  37. }
  38.  
  39. function user_queue_member_admin_validate($form, &$form_state) {
  40.   die();
  41.   if ($form_state['values']['profile_field']) {
  42.     /* parse the profile field */
  43.     if (!preg_match("^.*\[([0-9]+)\]$", $form_state['profile_field'], $matches)) {
  44.       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.');
  45.       return;
  46.     }
  47.     /* see if the fid exists */
  48.     if (!$field = db_fetch_object(db_query('SELECT f.name, f.fid FROM {profile_fields} f WHERE f.fid = %d', $matches[1]))) {
  49.       form_error($form['profile_field'], 'Profile field does not exist, you can keep it blank if you do not want to use phone number.');
  50.       return;
  51.     }
  52.     $form_state['fid'] = $field->fid;
  53.   }
  54. }
  55.  
  56. function user_queue_member_admin_submit($form, &$form_state) {
  57.   die();
  58.   if ($form_submit['fid']) {
  59.     variable_set(USER_QUEUE_MEMBER_PHONE_NUMBER, $form_submit['fid']);
  60.   }
  61. }
  62.  
  63. function user_queue_member_admin_autocomplete($string) {
  64.   $matches = array();
  65.   $result = db_query_range("SELECT f.name, f.fid FROM {profile_fields} AS f WHERE LOWER(f.name) LIKE LOWER('%s%%')", $string, 0, 10);
  66.   while ($data = db_fetch_object($result)) {
  67.     $matches[$data->name .' ['. $data->fid .']'] = check_plain($data->name);
  68.   }
  69.   drupal_json($matches);
  70. }