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"> 
        echo CHtml::dropDownList('district_id','',
        array(4=>'Gulbarga',3=>'Bangalore Urban'),
            'prompt'=>'Select District',
            'ajax' => array(
            echo CHtml::dropDownList('taluk_id','', array(), array('prompt'=>'Select a Taluk'));

in my InquiriesController.php :

public function actionLoadTaluk()
        array(':district_id'=>(int) $_POST['district_id']));
        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) :

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;
        return new CActiveDataProvider($this, array(
public static function model($className=__CLASS__)
        return parent::model($className);

Somebody Help me Please.. Thank you in advance.

#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 -

Thanks & regards,


Follow me - @rohisuthar


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

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