基于会话的多步形式cakephp [英] session based multistep form cakephp

查看:177
本文介绍了基于会话的多步形式cakephp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有3种形式。
我有一个动作在我的形式,我想创建3步骤形式使用会话。
我想当我点击下一个按钮,它验证form1,如果成功然后重定向到form2 ..
明智的form3,但保留所有的数据在会话中,在第三步动作去运行和添加所有的数据到数据库。

我只需要检查条件从会话,我的插入运行在我的动作addjob。
Plz帮助我做到这一点。

Basically i have 3 forms. I have one action in my form and i want create 3 steps form using session. I want when i click the next button it validates the form1,if successful then redirects to form2.. like wise for form3 but keep all the data in session and in third step the action goes runs and add all the data to database.
I only need to check conditions from session before my insert goes run in my action addjob. Plz help me to do this.

我的主要问题是如何获取所有的post数据在一个会话变量,并检查一步一步之前插入..

My main question is how to get all the post data in one session variable and check step by step before insert..

我是cakephp的学习者,我对会话不够了解。
如果你是一个专家,然后plz做这个。

i am learner in cakephp and i have not enough idea about session. if you are a expert then plz do this.

 public function addjob($id = NULL) {   
    $this->layout = "layout_registration_old";        
    $this->loadcategory();
    $this->loadcargo(); 
   //$this->loadsubcategory(); 
    $this->getCountries(); 
    $this->getstates(); 
    if ($this->request->is('put') || $this->request->is('post')) {          
        if (isset($id)) {
            $this->Job->id = $id;
        } else {
            $this->request->data['Job']['status'] = 1;  
            $this->request->data['Job']['job_type'] = 1; //this is used to update the job type private or public.
            $this->Job->create();
        }
        $this->Job->set($this->request->data);
        if ($this->Job->AddEdit()) { // ADDEdit is the validation name in model              
            if ($this->Job->save($this->request->data['Job'], false)) {
                if (isset($id)) {
                $this->Session->setFlash(__('Job has been updated sucessfully.'));

                } else {
                $this->Session->setFlash(__('Job has been added succesfully.'));

                }
                $this->redirect(array('controller' => 'jobs', 'action' => 'index'));
            }
        } else {
            $errors = $this->Job->validationErrors;

            $this->Session->setFlash(__('Please check your entry.'), 'flash_error');
        }
    }
    if (isset($id)) {
        $this->request->data = $this->Job->find('first', array('conditions' => array('id' => base64_decode($id))));
    }

}   

form - 1

 <?php echo $this->Form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'addjob')));?>

     <?php echo $this->Form->input('customer_name',array('div' => false, 'label' => false));?>
      <?php echo $this->Form->input('customer_no',array('div' => false, 'label' => false));?>
       <?php echo $this->Form->input('customer_email',array('div' => false, 'label' => false));?>
       <?php
                  echo $this->Form->input('transport_type', array(
                      'type' => 'select',
                      'label' => false,
                     'class' => 'select',
                      'options' => array(
                          1 => 'Road'
                      ),                

                  ));
              ?>
 <?php echo $this->Form->submit('Save', array('class' => "navigation_button btn btn-primary btn-sm", 'div' => false)); ?>
        <?php echo $this->Form->end(); ?>

form - 2

 <?php echo $this->Form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'addjob')));?>

 <?php echo $this->Form->input('fname',array('div' => false, 'label' => false));?>
  <?php echo $this->Form->input('lname',array('div' => false, 'label' => false));?>
   <?php echo $this->Form->input('email',array('div' => false, 'label' => false));?>
   <?php echo $this->Form->submit('Save', array('class' => "navigation_button btn btn-primary btn-sm", 'div' => false)); ?>
    <?php echo $this->Form->end(); ?>

form - 3

    <?php echo $this->Form->create('Job', array('url' => array('controller' => 'jobs', 'action' => 'addjob')));?>

     <?php echo $this->Form->input('shop',array('div' => false, 'label' => false));?>
      <?php echo $this->Form->input('business',array('div' => false, 'label' => false));?>
       <?php echo $this->Form->input('status',array('div' => false, 'label' => false));?>  
 <?php echo $this->Form->submit('Save', array('class' => "navigation_button btn btn-primary btn-sm", 'div' => false)); ?>
        <?php echo $this->Form->end(); ?>


推荐答案

会话,您应该使用任何 javascript解决方案(表单向导)实现多部分表单。使用javascript或通过ajax(如果需要动态完成)之前,请先验证每个步骤的数据,然后再移至下一步骤在最后提交表单,这样就不必播放会话。

Instead of saving the data from first 2 forms in a session, you should implement a multi part form using any javascript solution (Form wizard). Validate the data of each step using javascript or via ajax (if needs to be done dynamically) before moving to the next step and submit form at the end so that you don't have to play with sessions.

示例链接

PS - 这可以作为对该问题的评论,但我还没有获得足够的声誉来发表评论:(

PS - This could go as a comment to the question but I haven't gained enough reputations to post comments yet :(

这篇关于基于会话的多步形式cakephp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆