0

I am trying to render the form element below in telisim module but it's not working, no output (see the screenshot). enter image description here

The telisim.module file looks as follow:

//hook_menu

function telisim_menu() {
    $items['simcodes'] = array(
    'title' => 'SIM CODES',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('telisim_examples'),
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

/**
* Implements hook_element_info().
*/

function telisim_element_info() {
  return array(
    'telisim_notepad' => array(
      '#input' => TRUE,
      '#process' => array('porta_teslisim_notepad_process_callback'),
      '#theme_wrappers' => array('telisim_inline_form_element'),
    ),
  );
}

function porta_teslisim_notepad_process_callback($element, &$form_state, $complete_form) {

 $element['#tree'] = TRUE;

  // Normal FAPI field definitions, except that #value is defined.
  $element['areacode'] = array(
    '#type' => 'textfield',
    '#size' => 3,
    '#maxlength' => 3,
    '#value' => $element['#value']['areacode'],
    '#required' => TRUE,
    '#prefix' => '(',
    '#suffix' => ')',
  );
  $element['prefix'] = array(
    '#type' => 'textfield',
    '#size' => 3,
    '#maxlength' => 3,
    '#required' => TRUE,
    '#value' => $element['#value']['prefix'],
  );
  $element['extension'] = array(
    '#type' => 'textfield',
    '#size' => 4,
    '#maxlength' => 4,
    '#value' => $element['#value']['extension'],
  );

   return $element;

  }

  function _telisim_element_theme() {
  return array(
    'telisim_inline_form_element' => array(
      'render element' => 'element',
      'file' => 'telisim.module',
    ),
    'telisim_checkbox' => array(
      'render element' => 'element',
      'file' => 'telisim.module',
    ),
  );
}


function telisim_examples($form, &$form_state){

  $form['a_form_example_element_discrete'] = array(
    '#type' => 'telisim_notepad',
    '#title' => t('Discrete phone number'),
    '#default_value' => variable_get(
      'form_example_element_discrete',
      array(
        'areacode' => '999',
        'prefix' => '999',
        'extension' => '9999',
      )
    ),
    '#description' => t('A phone number : areacode (XXX), prefix (XXX) and extension (XXXX).'),
  );

   dsm($form);
    return $form;
}
1

I see two problems:

1) Your hook_theme() implementation is named incorrectly, meaning it will never be called. This:

_telisim_element_theme()

Should be this:

telisim_theme()

2) You haven't implemented theme_telisim_inline_form_element(), so there is no HTML for the form element to render.

You need to create this function, and output the relevant HTML for your form element inside the function.

| improve this answer | |
  • Should just be function telisim_theme() to stay in line with all the others hooks, but yeah, this basically – Clive Feb 5 '17 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.