MultiModelForm: Not getting validated

I've followed the usage method of MultiFormModel extension from the extension page. But after i submit the form, nothing happens. The form is not getting validated or saved.

Here is actionCreate:

public function actionCreate()
    {
        Yii::import('ext.multimodelform.MultiModelForm');

            $model=new Product;
            $spec=new ProductSpec;
            $validatedMembers = array();
            $category=Category::model()->findAll(array('order'=>'category_name'));
            // Uncomment the following line if AJAX validation is needed
            // $this->performAjaxValidation($model);

            if(isset($_POST['Product']))
            {
                    $model->attributes=$_POST['Product'];
                    if(MultiModelForm::validate($spec,$validatedMembers,$deleteItems) && $model->save())
                    {
                            $masterValues = array ('product_id'=>$model->id);
                            if (MultiModelForm::save($spec,$validatedMembers,$deleteMembers,$masterValues))
                                    $this->redirect(array('view','id'=>$model->id));
                    }       
            }

            $this->render('create',array(
                    'model'=>$model,
                    'category'=>$category,
                    'spec'=>$spec,
            'validatedMembers' => $validatedMembers,
            ));
    }

In create.php,

<?php echo $this->renderPartial('_form', array('model'=>$model,'category'=>$category,       'spec'=>$spec, 
    'validatedMembers' => $validatedMembers,)); ?>

In _form.php

<?php

            // see http://www.yiiframework.com/doc/guide/1.1/en/form.table
            // Note: Can be a route to a config file too,
            //       or create a method 'getMultiModelForm()' in the member model

            $memberFormConfig = array(
                  'elements'=>array(
                    'field1'=>array(
                        'type'=>'text',
                        'maxlength'=>40,
                    ),
                    'field2'=>array(
                        'type'=>'text',
                        'maxlength'=>40,
                    ),

                ));

            $this->widget('ext.multimodelform.MultiModelForm',array(
                    'id' => 'id_member', //the unique widget id
                    'formConfig' => $memberFormConfig, //the form configuration array
                    'model' => $spec, //instance of the form model

                    //if submitted not empty from the controller,
                    //the form will be rendered with validation errors
                    'validatedItems' => $validatedMembers,

                    //array of member instances loaded from db
                    'data' => $spec->findAll('product_id=:prodId',   array(':prodId'=>$model->id)),
                ));
    ?> 

Product Model

Product Model:

<?php
  class Product extends CActiveRecord
  {

public static function model($className=__CLASS__)
{
    return parent::model($className);
}


public function tableName()
{
    return 'product';
}


public function rules()
{

    return array(
        array('name, menu_entry, shown_in_menu, content, category_id', 'required'),
        array('shown_in_menu, category_id', 'numerical', 'integerOnly'=>true),
        array('name, menu_entry', 'length', 'max'=>200),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, name, menu_entry, shown_in_menu, content, category_id', 'safe', 'on'=>'search'),
    );
}


public function relations()
{

    return array(
        'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
        'productSpecs' => array(self::HAS_MANY, 'ProductSpec', 'product_id'),
    );
}


public function attributeLabels()
{
    return array(
        'id' => 'ID',
        'name' => 'Name',
        'menu_entry' => 'Menu Entry',
        'shown_in_menu' => 'Shown In Menu',
        'content' => 'Content',
        'category_id' => 'Category',
    );
}


public function search()
{


    $criteria=new CDbCriteria;

    $criteria->compare('id',$this->id);
    $criteria->compare('name',$this->name,true);
    $criteria->compare('menu_entry',$this->menu_entry,true);
    $criteria->compare('shown_in_menu',$this->shown_in_menu);
    $criteria->compare('content',$this->content,true);
    $criteria->compare('category_id',$this->category_id);

    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
    ));
}
}

ProductSpec Model:

<?php


 class ProductSpec extends CActiveRecord
 {

public static function model($className=__CLASS__)
{
    return parent::model($className);
}

/**
 * @return string the associated database table name
 */
public function tableName()
{
    return 'product_spec';
}

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('product_id, field1, field2', 'required'),
        array('product_id', 'numerical', 'integerOnly'=>true),
        array('field1, field2', 'length', 'max'=>1000),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, product_id, field1, field2', 'safe', 'on'=>'search'),
    );
}


public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
        'product' => array(self::BELONGS_TO, 'Product', 'product_id'),
    );
}

/**
 * @return array customized attribute labels (name=>label)
 */
public function attributeLabels()
{
    return array(
        'id' => 'ID',
        'product_id' => 'Product',
        'field1' => 'Field1',
        'field2' => 'Field2',
    );
}


public function search()
{
    // Warning: Please modify the following code to remove attributes that
    // should not be searched.

    $criteria=new CDbCriteria;

    $criteria->compare('id',$this->id);
    $criteria->compare('product_id',$this->product_id);
    $criteria->compare('field1',$this->field1,true);
    $criteria->compare('field2',$this->field2,true);

    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
    ));
}
}

Answers


Finally got it done using these.

JQRelcopy

and

Update two models from one view.


Need Your Help

Java: Exception itself is null

java android null bluetooth ioexception

I am pretty confused its an android problem or Java problem it self.

Cordova/Phonegap/Ionic - Receiving Push message via PushPlugin and save data to localStorage even when user dismisses the notification

android cordova google-cloud-messaging ionic-framework phonegap-pushplugin

I have set up an Ionic Framework project which receives GCM push notifications. I want to save the incoming notifications in the window.localStorage of the app.