title: How to render an element from a controller in cakephp?
body: <p>I am having trouble figuring this out. I have an element named quoteform in my default layout. This element has a form which has a few textboxes, checkboxes, submit button etc. I would like to submit the form and send a mail with all this data. On successfully sending the mail, I would like to replace the current div with another div which says Message sent successfully.</p>
  
  <p>I have used cakephp ajax to do this but on submit, it doesnt send a mail or refresh the div with the message.</p>
  
  <p>Following is my code</p>
  
  <p><em>Quotes/quoteform.ctp</em></p>
  
  <pre><code>&lt;?php
  $this-&gt;requestAction('Quotes/index');
  ?&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"&gt;&lt;/script&gt;
  &lt;div id="quotenext"&gt;
      &lt;?php echo $this-&gt;Form-&gt;create('Quote'); ?&gt;
      &lt;div class="inputboxa"&gt;&lt;?php echo $this-&gt;Form-&gt;input(
              'name', array(
              'id' =&gt; 'name',
              'style' =&gt; 'width:440px;height:20px;font-size:8pt; background-color:black;color:white;resize:none;border:none;padding-left:5px;padding-top:5px;',
              'placeholder' =&gt; 'NAME*', 'type' =&gt; 'textarea'
          )); ?&gt;&lt;/div&gt;
      &lt;br&gt;
  
      &lt;div class="inputboxb"&gt;&lt;?php echo $this-&gt;Form-&gt;input(
              'email', array(
              'id' =&gt; 'email', 'placeholder' =&gt; 'E-MAIL*',
              'style' =&gt; 'width:440px;font-size:8pt;height:20px;resize:none;background-color:black;color:white;border:none;padding-left:5px;padding-top:5px;',
              'type' =&gt; 'textarea'
          )); ?&gt;&lt;/div&gt;
      &lt;br&gt;
  
      &lt;div class="inputboxc"&gt;&lt;?php echo $this-&gt;Form-&gt;input(
              'phone', array(
              'id' =&gt; 'phone', 'placeholder' =&gt; 'PHONE*',
              'style' =&gt; 'width:440px;font-size:8pt;height:20px;resize:none;background-color:black;color:white;border:none;padding-left:5px;padding-top:5px;',
              'type' =&gt; 'textarea'
          )); ?&gt;&lt;/div&gt;
      &lt;br&gt;
  
      &lt;?php
  
      echo $this-&gt;Js-&gt;submit(
          'SUBMIT', array(
          'success' =&gt; $this-&gt;Js-&gt;get('#quotenext')-&gt;effect('hide'),
          'update' =&gt; $this-&gt;Js-&gt;get('#quotesent')-&gt;effect('show')
      )); ?&gt;
      &lt;!--&lt;/a&gt;--&gt;
      div id="quotesent" class="slide" style="display:none""&gt;
  
  
      &lt;div id="quotebottom"&gt;
          &lt;div id="message"&gt;
              &lt;?php echo $this-&gt;Session-&gt;flash(); ?&gt;
              &lt;div id="closediv"&gt;CLOSE&lt;/div&gt;
              &lt;?php echo $this-&gt;Form-&gt;end(); ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><em>QuotesController.php</em></p>
  
  <pre><code>class QuotesController extends AppController {
      public $helpers = array('Js' =&gt; array('jquery1.9.1.min'));
      public $components = array('RequestHandler');
  
      public function index() {
  
          $email = new CakeEmail();
  
          if ($this-&gt;request-&gt;is('post')) {
              $this-&gt;Quote-&gt;set($this-&gt;request-&gt;data);
              if ($this-&gt;Quote-&gt;save($this-&gt;request-&gt;data)) {
                  if ($this-&gt;RequestHandler-&gt;isAjax()) {
  
                      $name = $this-&gt;request-&gt;data['Quote']['name'];
                      $mail = $this-&gt;request-&gt;data['Quote']['email'];
                      $email-&gt;from(array($mail =&gt; $name));
                      $email-&gt;to('anniecherian79@gmail.com');
                      if (isset($this-&gt;request-&gt;data['Quote']['solutioncheckbox'])) {
                          $ctime = implode(',', $this-&gt;request-&gt;data['Quote']['solutioncheckbox']);
                      }
                      $message = "Phone No : " . $this-&gt;request-&gt;data['Quote']['phone'] . "\n\nBest Contact time :" . $ctime . " \n\nMessage : " . $this-&gt;request-&gt;data['Quote']['message'];
                      $email-&gt;subject('BlackNova Website Instant Quote Form');
                      $email-&gt;send($message);
  
                      if ($email-&gt;send($message)) {
                          $this-&gt;Session-&gt;setFlash('Quote Processed..Thank You For Visiting Our Website!!!');
                          $this-&gt;render('/view/elements/quotes/quoteform.ctp');
  
                      }
                  }
  
  
              }
          }
      }
  }
  </code></pre>
  
  <p>In short, on successfully ending the mail, I would like to display the message in #quotesent, is this possible?</p>