Yii Framework Forum: Dependant Dropdown Error Cannot Be Left Blank In Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Dependant Dropdown Error Cannot Be Left Blank In Yii

#1 User is offline   vaijanath 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 09-October 13
  • Location:Bengaluru

Posted 10 July 2014 - 02:10 AM

I have made 2 dependant dropdown in yii which works fine. But, even after selecting values from dropdown list, when i submit(create) form, Its showing below error :
Please fix the following input errors:
Taluk cannot be blank.
District cannot be blank .

And values are not inserting into the database. I have followed Everithing given in My link and My link

Here is my code in view(_form.php) :

<div class="row"> 
    <?php                                   
        echo CHtml::dropDownList('district_id','',
        array(4=>'Gulbarga',3=>'Bangalore Urban'),
        array(
            'prompt'=>'Select District',
            'ajax' => array(
                'type'=>'POST', 
                'url'=>CController::createUrl('loadTaluk'),
                'update'=>'#taluk_id', 
                'data'=>array('district_id'=>'js:this.value'),
            ))); 
            echo CHtml::dropDownList('taluk_id','', array(), array('prompt'=>'Select a Taluk'));
    ?>
</div>


in my InquiriesController.php :

public function actionLoadTaluk()
    {
        $data=Taluk::model()->findAll('district_id=:district_id',
        array(':district_id'=>(int) $_POST['district_id']));
        $data=CHtml::listData($data,'taluk_id','name');
        echo "<option value=''>Select a Taluk</option>";
        foreach($data as $value=>$name)
        echo CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);
    }


Here is my Model(Inquiries.php) :

<?php
public function rules()
    {   
        return array(
            array('organization, aplication_type, contact_person, pan, city_town_village, taluk_id, district_id', 'required'),
            array('organization, email', 'length', 'max'=>200),
            array('aplication_type, contact_person, pan', 'length', 'max'=>100),
            array('phone', 'length', 'max'=>60),
            array('address', 'length', 'max'=>150),
            array('pin_code', 'length', 'max'=>6),
            array('city_town_village', 'length', 'max'=>128),
            array('taluk_id, district_id', 'length', 'max'=>10),
            array('inquiry_id, organization, aplication_type, contact_person, email, phone, pan, address, pin_code, city_town_village, taluk_id, district_id', 'safe', 'on'=>'search'),
        );
    }
public function relations()
    {
        return array(
            'taluk' => array(self::BELONGS_TO, 'Taluk', 'taluk_id'),
        );
    }
public function attributeLabels()
    {
        return array(
            'inquiry_id' => 'Inquiry',
            'organization' => 'Organization',
            'aplication_type' => 'Aplication Type',
            'contact_person' => 'Contact Person',
            'email' => 'Email',
            'phone' => 'Phone',
            'pan' => 'Pan',
            'address' => 'Address',
            'pin_code' => 'Pin Code',
            'city_town_village' => 'City Town Village',
            'taluk_id' => 'Taluk',
            'district_id' => 'District',
        );
    }
public function search()
    {
        $criteria=new CDbCriteria;
        $criteria->compare('inquiry_id',$this->inquiry_id,true);
        $criteria->compare('organization',$this->organization,true);
        $criteria->compare('aplication_type',$this->aplication_type,true);
        $criteria->compare('contact_person',$this->contact_person,true);
        $criteria->compare('email',$this->email,true);
        $criteria->compare('phone',$this->phone,true);
        $criteria->compare('pan',$this->pan,true);
        $criteria->compare('address',$this->address,true);
        $criteria->compare('pin_code',$this->pin_code,true);
        $criteria->compare('city_town_village',$this->city_town_village,true);
        $criteria->compare('taluk_id',$this->taluk_id,true);
        $criteria->compare('district_id',$this->district_id,true);
        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
}


Somebody Help me Please.. Thank you in advance.
0

#2 User is offline   Rohit Suthar 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 247
  • Joined: 12-May 14
  • Location:Mumbai, India

Posted 24 July 2014 - 05:44 AM

Follow this wiki post -

http://www.yiiframew...th-dynamically/
Thanks & regards,

ROHIT SUTHAR
Mumbai(India)

Follow me - @rohisuthar

yii.at

If you found your solutions.... Don't hesitate to click on '+1' button
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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