2012-12-06 2 views
0

콘텐츠 이름, 성 ..... 등을 가지고있었습니다. 그리고 견인 drowpdownlist 국가와 인용, 국가 drowpdownlist 아약스에 의해 변경되면 인용, 그리고 모든 게 멋지다. 내 문제 :ajax에 의한로드 데이터는 valdiation return erorr이 사라졌을 때 사라졌습니다.

1- 제출을 클릭하고 유효성 검사에 오류가있는 경우 도시 값이 빈 값으로 바뀝니다 해결 방법?

2 $ form-> 사용 방법 도시 drowpdownlist를 의미합니다.

  • 양식 작업 Wrok

  • 양식 후 제출하고 사용자 이름과 같은 유효성 검사 오류를 반환 클릭 검증에 오류가 빈 .. 등 Error

보기없는 경우 :

 <div class="row"> 
     <?php echo $form->labelEx($model,'البلد'); ?> 
    <?php 

    /* 
    echo chtml::activeDropDownList($model,'country',$model->getcountry(),array('prompt'=>'اختر بلدك ') , 
    array(
'ajax' => array(
'type'=>'POST', //request type 
'url'=>CController::createUrl('current/dynamiccities'), //url to call. 
//Style: CController::createUrl('currentController/methodToCall') 
'update'=>'#city', //selector to update 
//'data'=>'js:javascript statement' 
//leave out the data key to pass all form values through 
)) 

    ); 

    */ 
    echo CHtml::activedropDownList($model,'country',$model->getcountry(), 

    array(
    'prompt'=>'اختر البلد أو المنطقة ', 
'ajax' => array(
'type'=>'POST', //request type 
'url'=>CController::createUrl('register/dynamiccities'), //url to call. 
//Style: CController::createUrl('currentController/methodToCall') 
'update'=>'#city', //selector to update 
//'data'=>'js:javascript statement' 
//leave out the data key to pass all form values through 
)) 
    ); 


    /// 




    //// 

    ?> 


     <?php echo $form->error($model,'country'); ?> 
    </div> 
    <div class="row"> 
     <?php echo $form->labelEx($model,'المدينة'); ?> 
     <?php 

echo CHtml::dropDownList('city','', array()); 





?> 
     <?php echo $form->error($model,'city'); ?> 
    </div> 
도시 부하 (210)

컨트롤러 : 사전

+2

최악의 코드를 말하지 말아라. 내 잘못을 말하면 안되지.이 플랫폼을 깎는 지식을 위해서 말야.) "최악의 코드는 내가 본 것"이 아니라. –

+0

나는 이것을 보았을 때 나 자신을 붙잡을 수 없다.) – Stranger

+0

하지만 그 코드에서 아무것도 찾을 수 없습니다. 디버거를 사용하여 코드를 단계별로 전달할 수 있습니다. – Stranger

답변

1

에서

public function actionDynamiccities() /// Call Ajax 
{ 


$country=intval($_POST['Users']['country']); 


     $data=Cities::model()->findAll('country_id=:country_id', 
        array(':country_id'=>$country)); 
    $data=CHtml::listData($data,'id','city_name_e'); 
    echo CHtml::tag('option', 
       array('value'=>''),CHtml::encode('Select Your City '),true); 

    foreach($data as $value=>$name) 
    { 
     echo CHtml::tag('option', 
        array('value'=>$value),CHtml::encode($name),true); 
    }; 


} 

덕분에 당신이이 줄에서

에코 CHTML : 드롭 다운리스트 ('도시', '', 배열())을 보면 ;

목록이 비어있는 것은 분명하며 나중에 콘텐츠를 편집하려는 경우에도 비어있게됩니다.

내가

에코 CHTML : DropDownList로 $ 모델 - (빈 ('도시', $ 모델 -> 도시> 국가) 배열()

같은 것을 사용하는 것이 좋습니다 것 : CHTML ::되는 listData (도시 :: 모델() -> findAllByAttributes (배열 ('country_id'=> $ 모델 -> 국가)), 'id', 'city_name_e')));

$model->country 또는 $model->country_id을 사용해야하는지 여부는 모델에 따라 다릅니다.

+0

감사합니다 jborch, 당신의 대답은 그렇게 논리적이지만, 내가 문제가 있었나요? dropDownList와 함께 사용하는 방법 ?? 미리 감사드립니다 –

+0

'echo CHtml :: dropDownList ('city, $ model-> city, empty ($ model-> country)? array() : Cities :: model() -> findAllByAttributes (array (' country_id '=> $ model-> country))); – jborch

+0

제출 후이 오류가 발생했습니다 도시 객체가 문자열로 변환 될 수 없습니다 http://im30.gulfup.com/DEfI1.png –

관련 문제