2015-12-23 44 views
1

這裏的問題是,如果用戶不填寫的地址重定向用戶通過自動打開的引導模式在CakePHP的控制器故障條件後重定向到模式(自動打開引導模式)

這裏填寫的模態地址是我的控制器這裏代碼

if ($this->request->is('post')) { 

     ['address_line_1']); 
     if($this->request->data['PropManagementAddress']['address_line_1'] == null){ 
     $this->redirect(array('#myModal')); 
     //$this->Session->setFlash(__('Add Address by pressing add button below')); 
     }else { 

     $this->PropManagementUser->create(); 
     if ($this->PropManagementUser->saveAll($this->request->data)) { 
      $this->Session->setFlash(__('The user has been saved.')); 
      return $this->redirect(array('action' => 'index')); 
     } else { 
      //prd($this->PropManagementUser->validationErrors); 
      $this->Session->setFlash(__('The user could not be saved. Please, try again.')); 
     } 
    } 

是我add.ctp代碼

<label>Add Address </label> 
<button type="button" class="form-group" style="margin-left:140px;"data-toggle="modal" data-target="#myModal">Add</button> 
<div class="modal fade" id="myModal" role="dialog"> 
    <div class="modal-dialog"> 
     <!-- Modal content--> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal">&times;</button> 
       <h4 class="modal-title">addrress</h4> 
      </div> 
      <div class="modal-body"> 
       <?php 
       echo $this->Form->input('PropManagementAddress.address_line_1',array('div' => array('class'=>'form-group'),'placeholder' => 'address line 1','label' => 'Address Line 1','class' => 'form-control')); 
       echo $this->Form->input('PropManagementAddress.address_line_2',array('div' => array('class'=>'form-group'),'placeholder' => 'address line 2','label' => 'Address Line 2','class' => 'form-control')); 
       echo $this->Form->input('PropManagementAddress.city_id',array('div' => array('class'=>'form-group'),'type'=>'select','options'=>$cities,'placeholder' =>'city id','label' => 'City ID','class' => 'form-control')); 
       echo $this->Form->input('PropManagementAddress.state_id',array('div' => array('class'=>'form-group'),'type'=>'select','options'=>$states,'label' => 'State ID','class' => 'form-control')); 
       echo $this->Form->input('PropManagementAddress.country_id',array('div' => array('class'=>'form-group'),'placeholder' =>'country id','label' => 'Country ID','class' => 'form-control')); 
       echo $this->Form->input('PropManagementAddress.pincode',array('div' => array('class'=>'form-group'),'type'=>'text','placeholder' => 'pincode','label' => 'Pincode','class' => 'form-control')); 
       echo $this->Form->input('PropManagementAddress.longitude',array('div' => array('class'=>'form-group'),'type'=>'text','placeholder' => 'longitude','label' => 'Longitude','class' => 'form-control')); 
       echo $this->Form->input('PropManagementAddress.latitude',array('div' => array('class'=>'form-group'),'type'=>'text','placeholder' => 'latitude','label' => 'Latitude','class' => 'form-control')); 
       ?> 

       <div class="modal-footer"> 
        <button type="button" class="btn btn-default" data-dismiss="modal">Save</button> 
       </div> 
      </div>  
     </div> 
    </div>  
+0

我試過的是這裏[只是看看這個鏈接](http://stackoverflow.com/questions/6323649/cakephp-can-i-redirect-to-a-specific-div-of-a-view -after-成功) – Fronto

回答

0

試試下面的辦法。

在你的控制器:

if ($this->PropManagementUser->saveAll($this->request->data)) { 
    $this->Session->setFlash(__('The user has been saved.')); 
    return $this->redirect(array('action' => 'index')); 
} else { 
    $this->Session->setFlash(__('The user could not be saved. Please, try again.')); 
    $this->set('showModal',true); 
} 

在你看來:

<?php if (!empty($showModal)):?> 
    <?php $this->Html->scriptStart(array('inline'=>false))?> 

     $('#myModal').modal('show'); 

    <?php $this->Html->scriptEnd()?> 
<?php endif ?> 

看到引導文檔.modal('show')

0

是啊我的答案了,我在CTP CakePHP的觀點

<script> 
$('#submit').click(function(e){ 
    if($.trim($('#address_line_1').val()) == ''){ 
     $("#myModal").modal("show"); 
     e.preventDefault(); 
     } 
}); 
</script> 

上面寫的模型中的文本框的ID腳本是地址行這是我要檢查空。