Add 2 form elements to Form via AJAX I am newbie into Drupal. 

I want to add 2 form elements dynamically to existing form via AJAX based on particular condition. But in the examples I saw till now the AJAX callback defined returns only one element to form. I tried to achieve this by adding these two fields in fieldset and returning fieldset as a single item. But this replaces my container div completely. This works only at first time and then the contents returned by callback replaces the container. 

function new_registration($form, &amp;$form_state) {
    $form['select-reason'] = array(
        '#type' =&gt; 'select',
        '#title' =&gt; t('Reason'),
        '#options' =&gt; array('' =&gt; 'Select') + _global_reasons(),
        '#description' =&gt; t('Reason.'),
        '#ajax' =&gt; array(
          'event' =&gt; 'change',
          'callback' =&gt; 'is_true',
          'wrapper' =&gt; 'options',
          'method' =&gt; 'replace'
        ),
      );

    $form['options'] = array(
        '#type' =&gt; 'container',
        '#prefix' =&gt; '&lt;div id="options"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;'
      );
    }

function is_true(&amp;$form, &amp;$form_state) {
      $product_quality = $form_state['values']['select-reason'];
      if(_belongs_check($product_quality)) {
          $form['a-add'] = array(
              '#type' =&gt; 'fieldset',
              '#collapsible' =&gt; FALSE,
              '#collapsed' =&gt; FALSE,
          );
          $form['a-add']['detail'] = array(
              '#type' =&gt; 'textfield',
              '#title' =&gt; t ( 'Details' ),
              '#description' =&gt; t ( 'Enter product name.' ),
              '#maxlength' =&gt; 400,
              '#size' =&gt; 100,
              '#required' =&gt; TRUE,
          );
          $form['a-add']['num'] = array(
              '#type' =&gt; 'textfield',
              '#title' =&gt; t ( 'Number' ),
              '#description' =&gt; t ( 'Enter number.' ),
              '#maxlength' =&gt; 400,
              '#size' =&gt; 100,
              '#required' =&gt; TRUE,
          );
      } else {
            //remove 2 fields added in IF block
      }
      return $form['a-add'];
    }


I also tried to return HTML structure of these two and place it in #markup type of form element. But I am not convinced with this way as theming might be complicated.
Can anybody help? Thanks in advance.
Add the additional form elements in the build function. The build function is rerun on every ajax request. If you don't have other things to do as modifying the form structure, then the ajax callback can be empty and you only need to return the new ajax container.

So you need to change this:

Put the new form elements inside the ajax container (in the first function):

$form['options']['a-add'][...]


And then return the whole container in the ajax callback (second function):

return $form['options'];


You always have to return the outside ajax div, otherwise the ajax callback will not work a second time.