how to dynamically add new fields to a form using ajax? I need to add the options array for a select field based on the first one 
like

&lt;?php

function lists_form_alter(&amp;$form,&amp;$form_state,$form_id){
    $governments=array();
  if($form_id == 'place_node_form'){
      /*$vocabularies=  taxonomy_get_vocabularies();

      foreach($vocabularies as $vocab){
          if($vocab-&gt;machine_name =='listings'){
              //
              //$_SESSION['vid']=$vocab-&gt;vid;
              break;
          }
      }*/
            $options=array();
      $g=taxonomy_get_tree(23,0,1,FALSE);
      $x=count($g);
      for($i=0;$i&lt;$x;$i++){
                $city[$i] = taxonomy_get_children($g[$i]-&gt;tid,23);
                      $options[$g[$i+1]-&gt;tid]=$g[$i]-&gt;name;
      }
      }
                  $options[0]='choose the government';

       $form['gov']=array('#title'=&gt;'Gov','#name'=&gt;'governorate','#type'=&gt;'select','#options'=&gt;$options,
           '#suffix'=&gt;'&lt;div id="replace"&gt;&lt;/div&gt;'
           ,'#ajax'=&gt;array('callback'=&gt;'ajax_callback','event'=&gt;'change','wrapper'=&gt;'replace','method'=&gt;'replace'));

isset($form_state['values']['governorate']) ? $op=taxonomy_get_children($form_state['values']['governorate'],23)
        : $op='';            
$form['city']=array("#title"=&gt;'City','#name'=&gt;'city','#type'=&gt;'select','#prefix' =&gt; '&lt;div id="replace"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;',
           '#options'=&gt; $op);

} 

function ajax_callback($form_state,$form){
    $form_state['rebuild']=true;
    return $form['city'];
}

?&gt;


what's wrong here?
You've got the parameters the wrong way round in your callback function; and you should probably take $form_state by reference if you need to change it:

function ajax_callback($form, &amp;$form_state){
  $form_state['rebuild']=true;
  return $form['city'];
}