Saving multi dimension array of post variables in model

Hi,

Thanks for the help. I have spend quite some time to figure this out. But I could not. Please help.

I have an user table with columns ‘email’ ‘fname’ ‘lname’.

User creates a team of people after filling out email, first name and last name. User adds few players on the form page and then submits them to be added in the user table above.

[u]

After submit, in the controller I am doing this[/u]

$model2 = new User(‘instant_create’);

		 if(isset($_POST['fname'],$_POST['lname'],$_POST['email']))


		 {


			  





			 $data=array('email'=>$_POST['email'],'lname'=>$_POST['lname'],'fname'=>$_POST['fname']);


			


			[b]$model2->attributes=$data;[/b] 

}

MODEL Looks Like

[b]public function rules()

{


	// NOTE: you should only define rules for those attributes that


	// will receive user inputs.


	return array(


	    array('email, password','required','on'=>'create'),	


		array('email','required','on'=>'instant_create'),	


		array('email','email'),		


		


	);


}

[/b]

I am getting this ERROR

[i][b]<h1>PHP Error [2]</h1>

<p>mb_strlen() expects parameter 1 to be string, array given (C:\xampp\htdocs\yii\framework\validators\CStringValidator.php:85)</p>

<pre>#0 unknown(0): CWebApplication->handleError()

#1 C:\xampp\htdocs\yii\framework\validators\CStringValidator.php(85): mb_strlen()

#2 C:\xampp\htdocs\yii\framework\validators\CValidator.php(197): CStringValidator->validateAttribute()

#3 C:\xampp\htdocs\yii\framework\base\CModel.php(158): CStringValidator->validate()

#4 C:\xampp\htdocs\yii\framework\db\ar\CActiveRecord.php(786): User->validate()

#5 C:\xampp\htdocs\mylls1\protected\controllers\homeController.php(57): User->save()

#6 C:\xampp\htdocs\yii\framework\web\actions\CInlineAction.php(50): HomeController->actionIndex()

#7 C:\xampp\htdocs\yii\framework\web\CController.php(309): CInlineAction->runWithParams()

#8 C:\xampp\htdocs\yii\framework\web\filters\CFilterChain.php(134): HomeController->runAction()

#9 C:\xampp\htdocs\yii\framework\web\filters\CFilter.php(41): CFilterChain->run()

#10 C:\xampp\htdocs\yii\framework\web\CController.php(1146): CAccessControlFilter->filter()

#11 C:\xampp\htdocs\yii\framework\web\filters\CInlineFilter.php(59): HomeController->filterAccessControl()

#12 C:\xampp\htdocs\yii\framework\web\filters\CFilterChain.php(131): CInlineFilter->filter()

#13 C:\xampp\htdocs\yii\framework\web\CController.php(292): CFilterChain->run()

#14 C:\xampp\htdocs\yii\framework\web\CController.php(266): HomeController->runActionWithFilters()

#15 C:\xampp\htdocs\yii\framework\web\CWebApplication.php(276): HomeController->run()

#16 C:\xampp\htdocs\yii\framework\web\CWebApplication.php(135): CWebApplication->runController()

#17 C:\xampp\htdocs\yii\framework\base\CApplication.php(162): CWebApplication->processRequest()

#18 C:\xampp\htdocs\mylls1\index.php(13): CWebApplication->run()

</pre>[/b]

[/i]

If I print $data.It looks like this. I do not know if I can save this to the model directly.

Array ( [email] => Array ( [0] => mickey@disney.com [1] => goofy@disney.com [2] => donald@disney.con ) [lname] => Array ( [0] => Mouse [1] => Wolf [2] => Duck ) [fname] => Array ( [0] => Mickey [1] => Goofy [2] => Donald ) )

you’ve messed something up. You should’ve called $model2->attributes=$_POST[‘User’]; Can you show your form code

Thanks for the reply

here is my form

Data collection in to array

[b]If loop(fields are dynamically created)

	var playerfname=&#036;('input:#fname').val();


	var playerlname=&#036;('input:#lname').val();


	var playeremail=&#036;('input:#email').val();


								


            myfname.push( playerfname);


            mylname.push( playerlname);


            myemail.push( playeremail);[/b]

Form submit

[b] $(‘form’).submit(function(){

	   &#036;.post(&quot;&lt;?php echo &#036;this-&gt;createUrl('index')?&gt;&quot;, { fname: myfname,lname: mylname,email: myemail} );

});[/b]

I changed my $data to below , but now no error but I am unable to do model2->save()

Array ( [0] => Array ( [fname] => Mickey [lname] => Mouse [email] => mickey@gmail.com ) [1] => Array ( [fname] => Donald [lname] => Duck [email] => donald@gmail.com ) )

I found exactly same issue in this forum unresolved

http://www.yiiframework.com/forum/index.php/topic/11110-model-attributes-error/

Hello, Did u find solution For dis issue?? I am facing same problem. I am unable to save this array

Array

(

[name] =&gt; Array


    (


        [0] =&gt; p1


        [1] =&gt; b1


    )





[designation] =&gt; Array


    (


        [0] =&gt; gjhgjj


        [1] =&gt; jhbjbb


       )





[contact_number] =&gt; Array


    (


        [0] =&gt; 878978


        [1] =&gt; 8897897


    )





[email_id] =&gt; Array


    (


        [0] =&gt; bjhhhjk


        [1] =&gt; mnbnn


    )

)

Please help