Yii Framework Forum: Problem With Collecting Tabular Input. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problem With Collecting Tabular Input. Rate Topic: -----

#1 User is offline   nakarin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 08-May 12

Posted 16 February 2013 - 10:18 AM

I want to know why $item->attributes = $_POST['Member'][$i]; won't work.Any body please help me.

In my controller.
        $items = $this->getItemsToUpdate($id);
        if (isset($_POST['Member'])) {
            foreach ($items as $i => $item) {
                if (isset($_POST['Member'][$i]))  {
                        $item->attributes = $_POST['Member'][$i];// This won't work,product_print won't update when saved.
                        $item->product_print=$_POST['Member'][$i]['product_print'];// This will work,product_print will be     update when saved
                        $item->save();
                  }
            }
        }
        $this->render('view', array(
            'model' => $this->loadModel($id),
            'items' => $items,
        ));
    }

    public function getItemsToUpdate($id) {
        $items = Member::model()->findAll('groupid=' . $id);
        return $items;
    }


In my view.
<?php foreach($items as $i=>$item): ?>
<?php echo CHtml::activeTextField($item,"[$i]product_print"); ?>
<?php endforeach; ?>

0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,670
  • Joined: 04-March 10
  • Location:UK

Posted 16 February 2013 - 10:39 AM

You need to make sure that product_print has a validation rule in the current scenario. If any value is acceptable, you can use the 'safe' rule.

array('product_print', 'safe'),

0

#3 User is offline   nakarin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 08-May 12

Posted 16 February 2013 - 10:55 AM

View PostKeith, on 16 February 2013 - 10:39 AM, said:

You need to make sure that product_print has a validation rule in the current scenario. If any value is acceptable, you can use the 'safe' rule.

array('product_print', 'safe'),



Thank you very much Keith,It 's working now. :rolleyes:
0

#4 User is offline   deiby.ramos 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 01-November 13

Posted 01 November 2013 - 03:59 PM

Compare rule in tabular input is not working.

Model class

class CustomReference extends Reference {

    public $retypeEmail;

    public function rules() {
        return(array_merge(parent::rules(), array(
                    array('retypeEmail', 'safe'),
                    array('retypeEmail', 'email'),
                    array('retypeEmail', 'compare', 'compareAttribute' => 'rf_email'),
        )));
    }

    public function attributeLabels() {
        return(array(
            'rf_code' => Yii::t('app', 'Rerence Code'),
            'rf_contact' => Yii::t('app', 'Reference Contact'),
            'rf_description' => Yii::t('app', 'Reference Description'),
            'rf_phone' => Yii::t('app', 'Reference Phone'),
            'rf_cellphone' => Yii::t('app', 'Reference Cellphone'),
            'rf_email' => Yii::t('app', 'Reference Email'),
            'rf_sp_code' => Yii::t('app', 'Reference Sp Code'),
            'rf_creationDate' => Yii::t('app', 'Reference Creation Date'),
            'rf_updateDate' => Yii::t('app', 'Reference Update Date'),
            'rf_user' => Yii::t('app', 'Reference User'),
            'rf_type' => Yii::t('app', 'Reference Type'),
            'retypeEmail' => Yii::t('magistral', 'Retype Reference Email'),
        ));
    }

}


View

foreach ($references as $reference) {            
                if ($i % 2 == 0)
                    echo '<div class="span12 margin-bottom-50">';

                echo '<div class="span6">';
                echo $form->textFieldRow($reference, "[$i]rf_contact", array('hint' => Yii::t('magistral', 'Introduce the name contact of the company'), 'class' => 'width-80-percent', 'labelOptions' => array('class' => 'bold-text')));
                echo $form->maskedTextFieldRow($reference, "[$i]rf_phone", '(+999)999-9999999)', array('hint' => Yii::t('magistral', 'Introduce the phone number like (+999)999-999999'), 'class' => 'width-80-percent', 'labelOptions' => array('class' => 'bold-text')));
                echo $form->textFieldRow($reference, "[$i]rf_email", array('hint' => Yii::t('magistral', 'Introduce the email like example@provide.com'), 'class' => 'width-80-percent', 'labelOptions' => array('class' => 'bold-text')));
                echo $form->textFieldRow($reference, "[$i]retypeEmail", array('hint' => Yii::t('magistral', 'Retype the email like example@provide.com'), 'class' => 'width-80-percent', 'labelOptions' => array('class' => 'bold-text')));
                echo $form->hiddenField($reference, "[$i]rf_type", array());
                echo '</div>';

                if ($i % 2 != 0)
                    echo '</div>';
                $i++;            
        }

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users