I have created a form using a custom module. I am working on ajax
functionality and updating markup
when user enter text in textfield
of the form.
Creating form in module
/**
* Implements hook_form().
*/
$form['name'] = array(
'#type' => 'textfield',
'#description' => 'Enter your name',
'#title' => 'Name',
'#size' => 50,
'#ajax' => array(
'callback' => 'custom_print_ajax_name_callback',
'wrapper' => 'custom-print-name',
'method' => 'replace',
),
);
$form['name_msg'] = array(
'#type' => 'item',
'#markup' => (!empty($form_state['input']['name']) ? $form_state['input']['name'] : ''),
'#prefix' => '<div id="custom-print-name">',
'#suffix' => '</div>',
);
Ajax submit callback:
/**
* Ajax callback
*/
function custom_print_ajax_name_callback($form, &$form_state) {
return $form['name_msg'];
}
Everything is working correctly except that when I checked HTML
of the page, an extra div
is added in HTML
of markup after updating ajax
as shown in below image.
I do not have any idea why is this extra div
rendering with markup
.
Thanks in advance.
custom_print_ajax_name_callback
?return $form['name_msg'];
. I have already added functioncustom_print_ajax_name_callback()
in question.item
type theme function as I don't know about it. I couldn't find any information about it anywhere..drupal
installation and using default theme and I have checkedhtml
beforeajax
and afterajax
and I only get extra 'div' afterajax
call. I have also checked source of html, as I am using, so it did not show any update html.