Example #1
0
echo $form->field($model, 'city')->dropDownList(ArrayHelper::map(Cities::find()->all(), 'id', 'name'), ['prompt' => 'Choose a City', 'onchange' => '$.post("' . Yii::$app->urlManager->createUrl('customers/lists') . '",{id:$(this).val()}, 
                                            function( data ) {
                                                $( "select#customers-suburb" ).html( data );
                                            });'])->label(false);
?>
                    </div>
                    <div class="col-lg-6">
                        <?php 
echo $form->field($model, 'street')->textInput(['maxlength' => true, 'placeholder' => $model->getAttributeLabel('street')])->label(false);
?>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6">
                        <?php 
echo $form->field($model, 'suburb')->dropDownList(ArrayHelper::map(Suburbs::find()->asArray()->all(), 'id', 'name'), ['prompt' => 'Choose a suburb'])->label(false);
?>
                    </div>
                    <div class="col-lg-6">
                        <?php 
echo $form->field($model, 'zipcode')->textInput(['maxlength' => true, 'placeholder' => $model->getAttributeLabel('zipcode')])->label(false);
?>
                    </div>
                </div>
            </div>
            <div class="col-lg-1"></div>
        </div>
    </div>

    <div class="form-group submit">
        <?php 
Example #2
0
 public function actionLists()
 {
     if (\filter_input(\INPUT_POST, 'id') != null) {
         $id = \filter_input(\INPUT_POST, 'id');
         $countPosts = Suburbs::find()->where(['city' => $id])->count();
         $posts = Suburbs::find()->where(['city' => $id])->orderBy('name ASC')->all();
         if ($countPosts > 0) {
             return $this->actionSuburbsList($posts);
         } else {
             return "<option>-</option>";
         }
     }
 }