在cakephp中提交表单后显示弹出消息

时间:2014-05-30 08:00:09

标签: cakephp

如何在cakephp

中将值提交到数据库后,在弹出框中显示确认消息

查看

<table style="border:none;width:100%;margin:0px;padding:0px;">
<tr>
    <td>Name</td>
    <td><?php echo $this->Form->input('sender_name', array(
        'label' => false, 'maxlength' => 100, 'style' => 'border:1px dashed gray;border-radius:5px;height:20px'
    )); ?></td>
     <td>E-Mail</td>
    <td><?php echo $this->Form->input('sender_email', array(
        'label' => false, 'maxlength' => 100, 'style' => 'border:1px dashed gray;border-radius:5px;height:20px'
    )); ?></td>
</tr>

<tr>
    <td style="vertical-align: top;">Your comment</td>
    <td><?php echo $this->Form->input('sender_comment', array(
        'label' => false, 'cols' => 50, 'rows' => 1, 'style' => 'border:1px dashed gray;border-radius:5px;'
    )); ?></td>
    <td colspan="2" align="center">
        <?php echo $this->Form->submit('Submit'); ?>
    </td>
</tr>

我在这里发表评论..发布评论后,我需要显示弹出消息

CONTROLLER

function newsdetail($id)
{
    $com = $this->comment->find('all', array('conditions' => array('comment.comment_id' => $id), 'order' => array('comment.post_time DESC')));
    $this->set('values', $com);
    if ($this->request->is('post')) {
        if ($this->comment->save($this->request->data)) {
            $this->Session->setFlash('Your message has been submitted');
        }
    }
}

此处消息显示在页面顶部..但我需要在弹出框中显示给我的消息。 谁可以帮助我...

2 个答案:

答案 0 :(得分:1)

首先在/ Views / Elements文件夹中创建flash消息元素,例如:popup.ctp

<script>
   alert("<?php echo $message; ?>");
</script>

在你的newsdetal函数中设置flash消息,如:

$this->Session->setFlash('Your message has been submitted','popup');

但我建议您使用一些jquery模式插件来获得积极的用户体验

答案 1 :(得分:0)

Try...
for message alert.
<?php
$msg = $this->Session->flash();
if (!empty($msg)) {
    echo "<script>alert('$msg');</script>";
}
?>