Tabular input , some rows can be left blank

I am unable to find the solution for it… When I click on save, it does not stores into the database…

Controller


public function actionCreate($mid)

	{

		 for($i=0;$i<5;$i++){

             $reviewers[$i]= new ReviewerBuffer();

             } 


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


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

		{

                    $valid = true;

                    foreach($reviewers as $i=>$review)

                    {    

                        if(isset($_POST['ReviewerBuffer'][$i])){

			$review->attributes=$_POST['ReviewerBuffer'][$i];

                        $review->manuscript_id = $mid;

                        $valid= $item->validate();

                        if($valid){

                            if(isset($_POST['ReviewerBuffer']['email'][$i]))

                                $review->save();

                           

                        }

                        

                        }

                        

                     }

                        }

               

                


		$this->render('create',array(

			'reviewers'=>$reviewers,

		));

	}



View _form




<div class="form">


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

	'id'=>'reviewer-buffer-form',

	'enableAjaxValidation'=>false,

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	

        <?php foreach($reviewers as $i=>$review): ?>

        <?php echo $form->errorSummary($review); ?>


	<div class="row">

		<?php echo $form->labelEx($review,'[$i]email'); ?>

		<?php echo $form->textField($review,'[$i]email',array('size'=>60,'maxlength'=>250)); ?>

		<?php echo $form->error($review,'[$i]email'); ?>

	</div>

        <?php endforeach; ?>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Save'); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- form -->



You need to make sure you have a rule defined for the email attribute. You could use the following:




array('email', 'email', 'allowEmpty'=>true),



If i do like this, other rows are stored in the database without the email field. But I do not want to store any thing in the database, if email field is not submitted

Just remove the ‘allowEmpty’ part if you need the email to be provided.

You might want to restate the problem you’re having because I’m not sure I understand the scenario.

I got the solution… I wanted to store the data in the database only when email is supplied by the user.

controller:




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

		{

                    $valid = true;

                    foreach($reviewers as $i=>$review)

                    {    

                        if(isset($_POST['ReviewerBuffer'][$i])){

			$review->attributes=$_POST['ReviewerBuffer'][$i];

                        $review->manuscript_id = $mid;

                        $valid= $review->validate();

                        if($valid){

                               // save only when email is provided

                               $post = $_POST['ReviewerBuffer'][$i];

                               if(isset($post['email'][$i])){

                                $review->save();}

                        

                            

                        

                     }}



I also tried with $_POST[‘ReviewerBuffer’][‘email’][$i]

but that does not seem to work