php - Cake php,在当前页面设置flash消息而不丢失表单内容

标签 php cakephp cakephp-1.3

在cake php中,是否可以在当前页面中设置flash消息而不丢失表单值。

这里提交了一个表单,那么我们需要在当前页面设置一条flash消息,并且不丢失表单值。 (不使用ajax/不使用​​Javascript)

表单已提交,转到 php 并设置 Flash 消息

HTML

<div class="videos form">
<?php echo $this->Form->create('Video');?>
    <fieldset>
        <legend><?php __('Add Video'); ?></legend>
    <?php
        echo $this->Form->input('video', array('label' => false, 'div' => false,'type' => 'file','style' =>'height:25px'));
        echo $this->Form->input('title');
        echo $this->Form->input('name');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>

PHP

function add()
{
    if (!empty($this->data)) {
        $file = $this->data['Video']['video'];
        $destination = 'files/videos/';
        $max_size = 100 * 1024 * 1024; //100 MB
        $allowed_types = array('mp4','flv','WebM','3GPP','avi','wmv','FLV','MP4','AVI','MOV');
        $status = $this->FileUpload->uploadFile($file, $destination, $max_size, $allowed_types, $filename);
        if ($status == "SUCCESS") {
            $userFile = $file['name'];
            $extension = pathinfo($userFile, PATHINFO_EXTENSION);
            $saveData = array(
                'name' => $filename . '.' . $extension,
                'path' => $destination
            );
            return $saveData;
        } else {
    // If this condition enters flash message is shown, but form values are lost
            return $status;
        }
    }
}

最佳答案

当您在该行设置之后将数据设置到文件时:

$this->Session->setFlash(__('your message', true));

以及您想要在该 View 文件中显示写入的位置:

<?php echo $this->Session->flash(); ?>

关于php - Cake php,在当前页面设置flash消息而不丢失表单内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9494205/

相关文章:

php - 检查复选框状态并基于它执行 PHP 查询

php - 使用 Propel 在数据库中增加值

php - 浏览器无法读取包含特殊字符的文件名

php - CakePHP : Validation message not displaying

timer - CakePHP 1.3 : Measuring Page Execution Time

带有 Laravel 的 PHP 无限脚本

unit-testing - 如何访问 CakePHP 2 测试用例中的夹具数据?

cakephp - cakephp 的 Netbeans v8.0.2 插件是否支持 cakephp v3?

mysql - 按序列号分组并选择该记录的最新(最后)创建日期

php - 用额外的字段保存 HABTM?