AJAX Form Creation new checkbox not replacing wrapper div

No replies
Last seen: 4 years 25 weeks ago
Joined: 2012-09-20


I have been experimenting with the code in "Using the #ajax attribute for dynamic form building" after finding other Drupal tutorials hard to follow. I am finding that the initial form displays as it should. When I select one of the Operating System choices I see the "wait a minute" icon but when it stops rotating I do not see the checkbox. Examining with Firebug I can see the empty wrapper div when the form is first loaded but it does not get filled with the checkbox as I would expect.

I have cut out the other form examples to get down to just the ajax example. Here is the code I am using.

function bmc_dealer_dashboard_menu()
$items['dealer-dashboard'] = array(
'title' => 'Dealer Dashboard',
'page callback' => 'bmc_dealer_dashboard',
'access callback' => TRUE,
return $items;

function bmc_dealer_dashboard_form($form_state)

// Added AJAX callback.
$form['computer_stats']['os'] = array(
'#title' => t('Operating system'),
'#type' => 'select',
'#options' => drupal_map_assoc(array('', t('OSX'), t('Linux'), t('Windows'))),
'#ajax' => array(
'callback' => 'input_test_callback',
'wrapper' => 'input_os_verify_wrapper',

// Setting an empty element with a wrapper to be populated.
$form['computer_stats']['os_verify'] = array(
'#type' => 'markup',
'#prefix' => '

'#suffix' => '


// When submitted, check for value of OS, and populate os_verify.
if (isset($form_state['values']['os'])) { // Fixed this line, was throwing an error in the original video code.
$form['computer_stats']['os_verify']['#type'] = 'checkbox';
$form['computer_stats']['os_verify']['#title'] = t('Are you sure you are using @os?', array('@os' => $form_state['values']['os']));

$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),

return $form;

function bmc_dealer_dashboard()
return drupal_get_form('input_test_form');


function input_test_callback($form, $form_state) {

Can anyone see what I might have broken or why the checkbox is not appearing where it should

Kind Regards


Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:

Contact us

Below are the supported keyboard shortcuts for our video player.

Start / stop video
Go to next video
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
Jump to a percentage (2 is 20%, for example)
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
1 month
6 months
10% off
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.