\BootstrapHorizontalAjaxModalForm
Defines an Ajax submitted Form within a Bootstrap Modal Window
<b>Usage</b>
<code>
new BootstrapHorizontalAjaxModalForm(
$this->controller,
$name = "MyForm",
$fields,
$actions,
$validator,
$title = 'My Form Modal Title',
new BootstrapModalFormAction($Title = 'Open My Modal Form')
)
</code>
To customize the functionality you can overwrite the javascript
<code>
$name = $this->FormName();
$action = $this->FormAction().'/'.$controller->urlParams['ID'];
$loading = _t('BootstrapAjaxModalForm.LOADING', 'BootstrapAjaxModalForm.LOADING');
Requirements::block('BootstrapAjaxModalForm_Js_'.$this->FormName());
$js = <<<JS
(function($){
$(function(){
$('#{$name}').ajaxForm({
delegation: true,
target: '#Modal_{$name} .modal-dialog .modal-content',
beforeSubmit: function(data, form, options){
$('#{$name} [type=submit]').prop("disabled", true).html('{$loading}');
}
});
});
$(function(){
$('#Modal_{$name}').on('show.bs.modal', function(e){
$('#Modal_{$name} .modal-dialog .modal-content').load('{$action}');
});
$('#Modal_{$name}').on('hidden.bs.modal', function(e){
$('#Modal_{$name} .modal-dialog .modal-content').html('');
});
});
})(jQuery);
JS;
Requirements::customScript($js, 'Custom_BootstrapAjaxModalForm_Js_'.$this->FormName());
</code>
Also you can controll the retur of your action
<code>
public function doSend(array $data){
// Do some stuff
// clear messages
$this->clearMessage();
// clear some form fields
$this->loadDataFrom(array('Title' => null, 'Text' => null));
// add some success message
$this->setMessage('You Message has been send', 'good');
// return the rendered Form for Ajax
return $this->forAjaxTemplate();
}
</code>
In the Controller the Form needs to be returned by AjaxReturn Method
<code>
public function InheritedBootstrapAjaxModalForm(){
// returnes the rendered form or the Form Object dependent on the request
return InheritedBootstrapAjaxModalForm::create($this, "InheritedBootstrapAjaxModalForm")->AjaxReturn($this->request);
}
</code>
Synopsis
- // Inherited members from BootstrapModalForm
- protected $ModalFormAction;
- protected $title;
- protected string $size;
- // methods
- public void IsHorizontal()
- public void __construct()
- // Inherited methods from BootstrapAjaxModalForm
- public void __construct()
- public void forAjaxTemplate()
- public void AjaxReturn()
- protected void examineFormAction()
- // Inherited methods from BootstrapModalForm
- public void hasErrors()
- public void setTitle()
- public void getTitle()
- public void setSize()
- public void setLarge()
- public void setSmall()
- public void setNormal()
- public void getSize()
- public void __construct()
Hierarchy
Extends
Members
protected
- $ModalFormAction
- $size
- $title
Methods
public
Inherited from BootstrapAjaxModalForm
protected
public
- AjaxReturn()
- forAjaxTemplate() — Return a rendered version of this form, suitable for ajax post-back.