Using ajax in my entityform I have a content type called Area and another content type called apartment that has a reference to area.

I have an Investment form (using entityform module) in which users select which area; after that, users should be able to see apartments in that area in a select box. (This feature should be implemented wit ajax.)

I want to have some filters on areas and apartments like views module filters (for example apartment which are not sold). How should I implement these features?

and here's my node--invest.tpl.php:

&lt;?php $language = $GLOBALS['language']; if ($language-&gt;language == $node-&gt;language): ?&gt;
    &lt;div class="panel"&gt;
        &lt;div class="viewport"&gt;
            &lt;div class="main match-height"&gt;
                &lt;div class="col-con"&gt;
                    &lt;div class="col-1-1"&gt;
                        &lt;?php echo $custom_content['body'] ?&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class="col-con"&gt;
                    &lt;?php foreach($custom_content['panels'] as $panel): ?&gt;
                        &lt;div class="col-1-2"&gt;
                            &lt;div class="roadmap"&gt;
                                &lt;h3&gt;&lt;?php echo $panel['title']?&gt;&lt;/h3&gt;
                                &lt;ul&gt;
                                    &lt;?php foreach($panel['steps'] as $step): ?&gt;
                                        &lt;li&gt;&lt;?php echo $step ?&gt;&lt;/li&gt;
                                    &lt;?php endforeach; ?&gt;
                                &lt;/ul&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;?php endforeach; ?&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="sidebar match-height"&gt;
                &lt;h3&gt;&lt;?php echo $custom_content['form_title'] ?&gt;&lt;/h3&gt;
                &lt;p&gt;&lt;?php echo $custom_content['form_body'] ?&gt;&lt;/p&gt;
                &lt;div class="form"&gt;
                    &lt;?php print drupal_render($entityform) ?&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;?php endif; ?&gt;


And if you wonder what is $custom_content, this is the code that generates it.

function get_invest_page_data($node) {
    $invest = [];
    $invest['title'] = $node['title'];
    $invest['body'] = $node['body'][0]['value'];
    $invest['form_title'] = $node['field_form_title'][0]['value'];
    $invest['form_body'] = $node['field_form_body'][0]['value'];
    $invest['panels'] = [];

    if ( ! empty($node['field_step_panel'])) {
        $i = 0;
        foreach ($node['field_step_panel'] as $panel_key) {
            $panel = load_collection($panel_key['value']);
            $panels[$i] = [];
            $invest['panels'][$i]['title'] = $panel-&gt;field_invest_panel_title['und'][0]['value'];

            $steps_keys = $panel-&gt;field_invest_panel_step;


            $j = 0;
            foreach ($steps_keys['und'] as $step_key) {
                $step = load_collection($step_key['value']);
                $invest['panels'][$i]['steps'][$j] = $step-&gt;field_invest_panel_step_body['und'][0]['value'];
                $j++;
            }


            $i++;
        }
    }

    return $invest;
}


This code exists in template.php.
The following line is used in theme_prepreprocess_node().

$node['custom_content'] = get_invest_page_data($node);
The ajax from a form is handled by the form function itself wich is edited in the mdule layer, not in the template layer. The custom module approach would be. 

Find the id of the entity form, see this Tutorial

Once you have the id you can use the MY_MODULE_form_FORM_ID_alter to edit the form elements to use ajax.
See this Tutorial for more info on ajax forms. 

If you want the ajax callback to alter an external element/several wrappers you can use the ajax_command_* functions to change pretty much anything selectable by JS. 
Have the ajax callback return something like this. (you won't need to set the #ajax wrapper in this case). 

More about the drupal's ajax_command_* functions

function AJAX_CALLBACK_CALLED_FROM_FIELD($form, &amp;$form_state){
  $commands[] = ajax_command_html('JQUERY_SELECTOR', 'VALID_HTML'); // Or any other valid ajax command. 
  return array( 
    '#type' =&gt; 'ajax', 
    '#commands' =&gt; $commands
  ); 
}