2013-09-30 2 views
0

임시 데이터를 내 양식에서 내 모델로 전달하려고합니다. 내 양식에 숨겨진 데이터가 있지만 내 모델에서 값을 가져 오지 못합니다.임시 데이터를 Yii의 숨겨진 필드에 다시 전달

나의 양식은 내가 jQuery를 사용하여 내 숨겨진 필드의 데이터를 던진 후 나는 내 양식의 유효성을 검사 proceeed

<?php echo $form->hiddenField($model, 'fieldName'); ?> 
<?php echo $form->labelEx($model,'name'); ?> 
<?php echo $form->textField($model,'name'); ?> 
<?php echo $form->error($model,'name'); ?> 

입니다. 검증 예외를 명중 할 때마다

public function rules() 
{ 
    return array(  
     array('name, email, subject, phone, body', 'required','message' => '{attribute} Required'), 
     array('resume', 'file', 'types'=>'txt,pdf,doc,docx', 'maxSize'=>2097152, 'tooLarge'=>'File has to be smaller than 2MB','allowEmpty'=>false), 
     array('email', 'email'), 
    ); 
} 

, 그것은 내가 숨겨진 양식에서 전송되는 데이터를 제외하고 입력 된 $_POST 모든 데이터를 반환합니다.

$_POST을 숨겨진 양식으로 되돌리려면 어떻게해야합니까?

답변

0

첫째로 설정해보십시오 : 속성선언 공공 모델에 있어야합니다.

public function rules() 
{ 
    return array(  
     array('name, email, subject, phone, body', 'required','message' => '{attribute} Required'), 
     array('resume', 'file', 'types'=>'txt,pdf,doc,docx', 'maxSize'=>2097152, 'tooLarge'=>'File has to be smaller than 2MB','allowEmpty'=>false), 
     array('email', 'email'), 
     array('fieldName','safe'), // Add the custom field to 'safe' mode. 
    ); 
} 
0

'fieldName'은 모델/테이블의 일부입니까? 그리고이 모델에 선언 단지 지정 속성이없는 경우, '안전'

+0

그래서 그것을 추가 할 것이다하십시오 안전 모드배열 ('fieldName에', '안전')와 필드규칙() 모델의

public $fieldName; 

추가 배열에? 배열 ('fieldName', '안전'); – marchemike

+0

예, 규칙 기능. – redGREENblue

관련 문제