gpt4 book ai didi

javascript - cakephp Controller 中的失败条件后重定向到模式(自动打开 Bootstrap 模式)

转载 作者:行者123 更新时间:2023-11-28 06:34:07 25 4
gpt4 key购买 nike

这里的问题是,如果用户未填写地址,则会重定向用户通过自动打开 Bootstrap 模态来填写模态地址

这是我的 Controller 代码

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>

最佳答案

尝试以下方法。

在你的 Controller 中:

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')在 Bootstrap 文档中。

关于javascript - cakephp Controller 中的失败条件后重定向到模式(自动打开 Bootstrap 模式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34436470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com