1

我很难弄清楚这一点。我的默认布局中有一个名为 quoteform 的元素。这个元素有一个表单,里面有一些文本框、复选框、提交按钮等。我想提交表单并发送包含所有这些数据的邮件。成功发送邮件后,我想用另一个 div 替换当前的 div,上面写着 Message sent successfully。

我已经使用 cakephp ajax 来执行此操作,但在提交时,它不会发送邮件或使用消息刷新 div。

以下是我的代码

行情/quoteform.ctp

<?php
$this->requestAction('Quotes/index');
?>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<div id="quotenext">
    <?php echo $this->Form->create('Quote'); ?>
    <div class="inputboxa"><?php echo $this->Form->input(
            'name', array(
            'id' => 'name',
            'style' => 'width:440px;height:20px;font-size:8pt; background-color:black;color:white;resize:none;border:none;padding-left:5px;padding-top:5px;',
            'placeholder' => 'NAME*', 'type' => 'textarea'
        )); ?></div>
    <br>

    <div class="inputboxb"><?php echo $this->Form->input(
            'email', array(
            'id' => 'email', 'placeholder' => 'E-MAIL*',
            'style' => 'width:440px;font-size:8pt;height:20px;resize:none;background-color:black;color:white;border:none;padding-left:5px;padding-top:5px;',
            'type' => 'textarea'
        )); ?></div>
    <br>

    <div class="inputboxc"><?php echo $this->Form->input(
            'phone', array(
            'id' => 'phone', 'placeholder' => 'PHONE*',
            'style' => 'width:440px;font-size:8pt;height:20px;resize:none;background-color:black;color:white;border:none;padding-left:5px;padding-top:5px;',
            'type' => 'textarea'
        )); ?></div>
    <br>

    <?php

    echo $this->Js->submit(
        'SUBMIT', array(
        'success' => $this->Js->get('#quotenext')->effect('hide'),
        'update' => $this->Js->get('#quotesent')->effect('show')
    )); ?>
    <!--</a>-->
    div id="quotesent" class="slide" style="display:none"">


    <div id="quotebottom">
        <div id="message">
            <?php echo $this->Session->flash(); ?>
            <div id="closediv">CLOSE</div>
            <?php echo $this->Form->end(); ?>
        </div>
    </div>
</div>

QuotesController.php

class QuotesController extends AppController {
    public $helpers = array('Js' => array('jquery1.9.1.min'));
    public $components = array('RequestHandler');

    public function index() {

        $email = new CakeEmail();

        if ($this->request->is('post')) {
            $this->Quote->set($this->request->data);
            if ($this->Quote->save($this->request->data)) {
                if ($this->RequestHandler->isAjax()) {

                    $name = $this->request->data['Quote']['name'];
                    $mail = $this->request->data['Quote']['email'];
                    $email->from(array($mail => $name));
                    $email->to('anniecherian79@gmail.com');
                    if (isset($this->request->data['Quote']['solutioncheckbox'])) {
                        $ctime = implode(',', $this->request->data['Quote']['solutioncheckbox']);
                    }
                    $message = "Phone No : " . $this->request->data['Quote']['phone'] . "\n\nBest Contact time :" . $ctime . " \n\nMessage : " . $this->request->data['Quote']['message'];
                    $email->subject('BlackNova Website Instant Quote Form');
                    $email->send($message);

                    if ($email->send($message)) {
                        $this->Session->setFlash('Quote Processed..Thank You For Visiting Our Website!!!');
                        $this->render('/view/elements/quotes/quoteform.ctp');

                    }
                }


            }
        }
    }
}

简而言之,在成功结束邮件后,我想在#quotesent 中显示消息,这可能吗?

4

0 回答 0