CakePHP:在控制器的ctp文件中显示表单后置值

时间:2015-11-20 12:30:41

标签: php ajax cakephp cakephp-2.0

我目前正在开发一个CakePHP Web应用程序,我已经通过ajax在formview.ctp创建了form submitted,但当我尝试在{{1}中显示表单值时来自未显示的控制器。

当我在控制器值中显示打印或回显变量时,如何在add.ctp文件中获取值并显示?

我想从add.ctp到控制器文件的ajax发布表单数据,我想在控制器的view.ctp文件中看到表单数据? CakePHP版本是2.0.13

View.ctp

add.ctp

添加Ctp

<?php echo $form->create('Review',array('action'=>'add/'.$listingData['Listing']['id'].'','id'=>'saveForm')); 

echo $form->input("starrating",array(
                    'title'=>__("Eek! Methinks not"),
                    'type'=>'radio',
                    'options'=>array('1' => '1'),
                    'class'=>'hover-star',
                    'value'=>'testing',

)
);  

echo $form->input("starrating",array(
                    'title'=>__("Meh. I've experienced better"),
                    'type'=>'radio',
                    'options'=>array('2' => '2'),
                    'class'=>'hover-star',
                    'value'=> '2',

)
);

echo $form->input("starrating",array(
                    'title'=>__("A-OK"),
                    'type'=>'radio',
                    'options'=>array('3' => '3'),
                    'class'=>'hover-star',
                    'value'=> '3',

)
);  

echo $form->input("starrating",array(
                    'title'=>__("Yay! I'm a fan"),
                    'type'=>'radio',
                    'options'=>array('4' => '4'),
                    'class'=>'hover-star',
                    'value'=> '4',

)
);

echo $form->input("starrating",array(
                    'title'=>__("Woohoo! As good as it gets!"),
                    'type'=>'radio',
                    'options'=>array('5' => '5'),
                    'class'=>'hover-star',
                    'value'=> '5',

)
);      


echo $form->end(); ?>

** Ajax&amp; Javascript **

<?php echo $this->pageStarRating;?>

控制器文件

$(document).ready(function () {
        $('.hover-star').rating({

        focus: function (value, link) {
                $("#hover-test").css("color", "#000");
                var tip = $('#hover-test');
                tip[0].data = tip[0].data || tip.html();
                tip.html(link.title || 'value: ' + value);

        },
        blur: function (value, link) {
                var tip = $('#hover-test');
                $('#hover-test').html(tip[0].data || '');

        },

        click: function (value, link) {
                var tip = $('#hover-test');
                tip.empty();


        },

        callback: function(value, link){
                var tip = $('#stick');
                tip.html(link.title || 'value: ' + value);

            }

        });

        $(".hover-star").click(function () {
            $("#hover-test").css("color", "#ff6a00");
            $('#saveForm').submit();

        });

        $(document).ready(function() {
                $('#saveForm').submit(function() {
                    var formData = $(this).serialize();
                    var formUrl = $(this).attr('action');

                      $.ajax({
                        type: 'POST',
                        url: formUrl,
                        data: formData,
                        success: function(data, textStatus, xhr) {
                            //alert(data);
                            window.location = formUrl;

                            },
                        error: function(xhr, textStatus, error) {
                            alert(textStatus);
                        }
                    });
                    return false;
                });
            });

0 个答案:

没有答案