在cakepp控制器出现故障后,重定向到模态(自动打开自举模态)
redirect to the modal ( automatic open bootstrap modal) after failing condition in cakephp 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">×</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>
尝试以下方法。
在您的控制器中:
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')
。
是的,我得到了答案,我在我的ctp cakefp视图中编写了脚本
<script>
$('#submit').click(function(e){
if($.trim($('#address_line_1').val()) == ''){
$("#myModal").modal("show");
e.preventDefault();
}
});
</script>
模型中上面的文本框id是address_line_1,我必须检查它是否为空。
相关文章:
- 如何捕获请求中的错误,然后打开模态,然后在模态使用RxJS关闭时重试
- 如何在提交按钮上触发模态&重定向Rails
- 模态中的JavaScript重定向
- 在nodejs中无需重定向即可将数据发送到模态
- 子操作不允许在我的模态形式中执行重定向操作
- 我开发了一个api,我希望它重定向到其他php页面,并在我点击api文件中的按钮时弹出模态
- Google PageSpeed Insights说我的网站很重.外部模态是一种解决方案吗?
- 如何使用 javascript 在模态窗口内重定向
- 模态中的 Django 形式:动态重定向和处理错误
- 在模态中使用 jquery 验证器后,从表单中重置/删除类
- 在模态中加载分部视图时发生错误时重定向到错误页面
- 在cakepp控制器出现故障后,重定向到模态(自动打开自举模态)
- 当点击rails中的提交按钮时,如何在重定向到下一页之前显示模态
- 重定向的页面是't提交模态表格后进行渲染
- 情态动词的形式.表单提交后需要重定向到模态
- 我怎么能重定向到第一个选项卡在模态弹出后,我关闭模态弹出
- 重置模态内容的正确方法是什么?
- 变量被重置为'1'在模态窗口
- 模态窗口内的Url重定向
- 如何在照片删除后重定向到模态