【问题标题】:How to perform any action before submit form in cake php在cake php中提交表单之前如何执行任何操作
【发布时间】:2014-07-04 13:06:08
【问题描述】:

我在 cake php 中有一个表单在这里我有一些隐藏字段,当用户单击提交按钮时我想发送这些字段。 在开始隐藏字段值为空白时,您可以在下面的给定表格中看到 我在 js 文件中的 playTimer() 函数中设置了隐藏字段值

但我的问题是当我要提交该表单时,它在帖子数据中的 actionId 隐藏字段具有空白值。我再次 clcik 提交然后我有值。

我想在用户第一次点击提交按钮时设置它,以便我在回调函数之前使用。

     echo $this->Form->create('Meditation', array('id' => 'timerform'));
     echo $this->Form->hidden('actionId', array('value'=>'', 'id'=>'actionId'));
     echo $this->Js->submit('Play', array(
                                            'before'    => 'playTimer();',
                                            'update'    => '#map_container',
                                            'complete'  => 'setsessionid();',   
                                            'success'   => 'soundPlay();resume();',
                                            'class'     => 'btn btn-med-success playTimer',
                                            'div'       => false,
                                            'async'     => false,
                                            'url'       => array('action' => 'timerupdateDuo')

                                ));



 ==========Custom.js============ 


      function playTimer(){


        $("#actionId").val('playTimer');

           }

谢谢

【问题讨论】:

    标签: cakephp


    【解决方案1】:
    <? echo $this->Form->submit(__('Save'), array(
                'class' => 'ClassOfTheFormSubmitBTN'
            )); ?>   
    
    <script type="text/javascript"> 
        $(function(){
           $('.ClassOfTheFormSubmitBTN').on('click',function(){
    
                      // implement your logic here
                      $('#MODELNAMEactionId').val('something');
    
                      //you can use ajax here with serialize to send the form 
                      //to stop the form from posting return false;
           });
        });
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-16
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      • 2020-03-13
      • 2017-03-20
      • 2022-06-15
      • 2012-02-01
      相关资源
      最近更新 更多