diff --git a/form_builder.js b/form_builder.js
index 32ab259..6be5ce6 100644
--- a/form_builder.js
+++ b/form_builder.js
@@ -15,6 +15,10 @@ Drupal.behaviors.formBuilderElement.attach = function(context) {
   if ($(context).is('div.form-builder-wrapper:not(.form-builder-processed)')) {
     $wrappers = $wrappers.add(context);
   }
+  // If the context itself is an element, add to the list.
+  else if ($(context).is('div.form-builder-element:not(.form-builder-processed)')) {
+    $elements = $elements.add(context);
+  }
 
   // Add a guard class.
   $wrappers.addClass('form-builder-processed');
@@ -154,6 +158,12 @@ Drupal.behaviors.formBuilderTabs.attach = function(context) {
 Drupal.behaviors.formBuilderDeleteConfirmation = {};
 Drupal.behaviors.formBuilderDeleteConfirmation.attach = function(context) {
   var $confirmForm = $('form.confirmation', context);
+
+  // If the confirmation form is the context.
+  if ($(context).is('form.confirmation')) {
+    $confirmForm = $(context);
+  }
+
   if ($confirmForm.length) {
     $confirmForm.submit(Drupal.formBuilder.deleteField);
     $confirmForm.find('a').click(Drupal.formBuilder.clickCancel);
@@ -504,7 +514,7 @@ Drupal.formBuilder.updateElement = function(response) {
     // Expand root level fieldsets after updating to prevent them from closing
     // after every update.
     $new.children('fieldset.collapsible').removeClass('collapsed');
-    Drupal.attachBehaviors($new.parent().get(0));
+    Drupal.attachBehaviors($new.get(0));
   }
 
   // Set the variable stating we're done updating.
diff --git a/includes/form_builder.admin.inc b/includes/form_builder.admin.inc
index 6ae7830..f0ae0bd 100644
--- a/includes/form_builder.admin.inc
+++ b/includes/form_builder.admin.inc
@@ -199,6 +199,9 @@ function form_builder_preview($f, &$form_state, $form, $form_type, $form_id) {
   $form['#attached']['js'][] = 'misc/form.js';
   $form['#attached']['js'][] = 'misc/collapse.js';
 
+  $form['#attached']['js'][] = array('data' => array('machineName' => array()), 'type' => 'setting');
+  $form['#attached']['js'][] = 'misc/machine-name.js';
+
   $settings = array(
     'emptyFieldset' => theme('form_builder_empty_fieldset'),
     'noFieldSelected' => theme('form_builder_no_field_selected'),
diff --git a/includes/form_builder.properties.inc b/includes/form_builder.properties.inc
index 21658cf..1ccb04a 100644
--- a/includes/form_builder.properties.inc
+++ b/includes/form_builder.properties.inc
@@ -17,9 +17,14 @@ function form_builder_property_key_form(&$form_state, $form_type, $element) {
 
   $form['key'] = array(
     '#title' => t('Form key'),
-    '#type' => 'textfield',
-    '#default_value' => $element['#key'],
-    '#required' => TRUE,
+    '#type' => 'machine_name',
+    '#default_value' => preg_match('/^new_[0-9]+$/', $element['#key']) ? '' : $element['#key'],
+    '#maxlength' => 128,
+    '#description' => t('The form key is used in the field "name" attribute. Must be alphanumeric and underscore characters.'),
+    '#machine_name' => array(
+      'source' => array('title'),
+      'label' => t('Form key'),
+    ),
     '#weight' => -9,
     '#element_validate' => array('form_builder_property_key_form_validate'),
   );
@@ -34,6 +39,31 @@ function form_builder_property_key_form_validate($element, $form_state) {
   if (!preg_match('/^[a-z0-9_]+$/', $element['#value'])) {
     form_error($element, t('The form key may only contain lowercase alphanumeric characters and underscores.'));
   }
+
+  // Check that the new key does not conflict with an existing key.
+  if ($element['#value'] != $element['#default_value']) {
+    $active_form = form_builder_active_form();
+    $form = form_builder_cache_load($active_form['form_type'], $active_form['form_id']);
+    $parents = $element['#parents'];
+    array_pop($parents);
+    $parents[] = $element['#value'];
+    $key_exists = FALSE;
+    foreach ($parents as $key) {
+      if (isset($form[$key])) {
+        $form = $form[$key];
+        $key_exists = TRUE;
+      }
+      else {
+        $key_exists = FALSE;
+        break;
+      }
+    }
+
+    if ($key_exists) {
+      form_error($element, t('The form key %key is already in use.', array('%key' => $element['#value'])));
+    }
+  }
+
 }
 
 /**
