本文介绍了在两个步骤中填写表单的正确性是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hy,

在两个步骤中填写表单的symfony中的正确性是什么?想象一下,我们有一个名为Enterprise的实体,我们希望创建一个仅包含必填字段和另一种形式的表单,当用户登录时可以填写其他非必填字段。

What is correctness in symfony to fill a form in two steps? Imagine that we have a entity called Enterprise and we want to create a form with only required fields and another form, that when the user login can fill the other non-required fields.

正确的形式如何?现在我有一个表单注册('lib / form / doctrine / EnterpriseForm.class.php')和另一个('lib / form / doctrine / EnterpriseCompleteForm.class.php')。在每个类中,我们设置标签,验证器。 ..但问题是第二种形式。当我尝试提交它给我一个错误,因为我没有发布必需的字段在模型中定义。我怎样才能做到这一点?是这样吗?如何解决这个问题?

How is the correctness form? Now i have a form to registration ('lib/form/doctrine/EnterpriseForm.class.php') and another ('lib/form/doctrine/EnterpriseCompleteForm.class.php').In every class we set labels, validators, ... but the problem is in the second form. When i try to submit it gives me an error because i have'nt post required fields defined in model. How can i do that? Is that way correct? How can i fix this?

谢谢。

推荐答案

,我做这个unset的变化,它的工作正常...但我有一个问题。我尝试对相同的动作进行更新。我的代码看起来像这样。

Well Felix, i do it "unset" changes and it works fine... but i have a problem. I try to do update on the same action. My code looks like that.

在动作

 public function executeStepOne(sfWebRequest $request){
    $this->form = new CustomerFormStepOne();

    if ($request->isMethod(sfRequest::POST)){
        $this->processRegisterForm($request, $this->form,'paso2');

    }else{
        $this->customer = Doctrine::getTable('Customer')-> find(1);
                $this->forward404Unless($this->customer);
    }   
  }

其中processRegisterForm代码是:

protected function processRegisterForm(sfWebRequest $request, sfForm $form,$route)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));    
    if ($form->isValid())
    {
      $customer = $form->save();  
      $this->redirect('customer/'.$route);
    }
  }

如果我尝试这样做,他们会给我一个错误'主键重复'。

if i try to do this they returns me an error 'primary key duplicate'.

这篇关于在两个步骤中填写表单的正确性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:55