2013-09-27 1 views
0

어떻게 양식 필드 값을 재설정 할 수 있습니까?symfony 1.4 실패 후 필드에서 값을 재설정

action: 
      $this->form = new $class(); 
      $this->form->bind($request->getParameter('signin')); 
      if ($this->form->isValid()) 
      { 
       $values = $this->form->getValues(); 
          $this->redirect('@example'); 
        } 
      else 
      { 
       if ($this->form->hasGlobalErrors()) 
        $this->errorclass = 'error'; 
      } 
      $this->form->resetFormFields(); 
      return $this->renderPartial('ajax/example); 

나는이 개 분야 이메일 및 PW 있습니다 : 비어 있음 오류가 발생한 후이를 resett 할을

이 그나마 작업 :(

$this->form->resetFormFields(); 

모든 솔루션 관해서 들으

답변

1
?

양식에 필드 (전자 메일 및 PW)가 2 개만있는 경우 간단히 양식을 다시 작성할 수 있습니다.

else 
{ 
    if ($this->form->hasGlobalErrors()) 
    $this->errorclass = 'error'; 
    $this->form = new $class(); 
} 

양식에 전자 메일 및 PW 만 아닌 필드가 더 있고 다른 필드 값을 유지하려는 경우 전자 메일 및 PW 값을 제거하고 새 양식을 바인딩 할 수 있습니다.

$values = $request->getParameter('signin'); 
$this->form->bind($values); 
if ($this->form->isValid()) 
{ 
    $this->redirect('@example'); 
} 
else 
{ 
    if ($this->form->hasGlobalErrors()) 
    $this->errorclass = 'error'; 
    $values['pw'] = ''; 
    $values['email'] = ''; 
    $this->form = new $class(); 
    $this->form->bind($values); 
}