preventing resetting of form fields after validation

Im new to yii. I am trying to create simple form with form validation. Whenever I enter wrong input there will be error message about the field but ALL OTHER FIELDS WILL GET RESET. How to prevent this? Any help is appreciated. Thanks.

are you passing in your controller all your form inputs to the model attributes?

yes. I am passing in controller.




if(isset($_POST['students']))

		{

			$model->attributes=$_POST['students'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->student_id));

		}




Its working fine when I am creating form fields for 1 table. But when I am creating fields for multiple tables in single form I am facing problem. Thanks.

mmm…

so you have in your form several inputs of the same db field right?

i think that might be part of the problem (the whole problem actually).

i never had to do it personally, and i’m extremely busy this week, but once i have enough time i’ll test it and look for a solution.

but i think you can find some article about it in the wiki or somewhere in the forum.

I appreciate your help. Thanks 4 ur time.

Any update on this issue? I am also facing similar problem.

When i am getting validation error, all the form values are getting reset.

Same here! I could really use some help!

Hi,

My form also holds more than 1 model and has an array of fields with the same name.

There was no time for me to figure out how to get it to work the proper Yii way so what I have done is create my own submit button


<input type="submit" value="Save" name="yt0" onClick="return myValidation()"> 

which calls a JS function


function myValidation(){

        sapNo = $('#Offer_SAP_NO').val();

	if(sapNo == ''){

		alert('SAP Number must be entered');

		return false; 

	} else {

		return true; 

	}

}

There was no need to touch the


<?php $form=$this->beginWidget('CActiveForm', array( ..... 

part.

Hope this will help some of you! I am very curious to know if anyone has the "proper" Yii answer to this!