Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
skeeks
/
cms-module-form
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Merge Requests
0
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2cd58c22
authored
Mar 18, 2015
by
semenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
86e514c8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
1 deletions
+87
-1
controllers/BackendController.php
+26
-0
views/blank-form.php
+2
-1
widgets/ActiveForm.php
+59
-0
No files found.
controllers/BackendController.php
View file @
2cd58c22
...
...
@@ -43,7 +43,33 @@ class BackendController extends Controller
*/
public
function
actionSubmit
()
{
if
(
\Yii
::
$app
->
request
->
isAjax
&&
!
\Yii
::
$app
->
request
->
isPjax
)
{
\Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$response
=
[
'success'
=>
false
,
'message'
=>
'Произошла ошибка'
,
];
if
(
$formId
=
\Yii
::
$app
->
request
->
post
(
Form
::
FROM_PARAM_ID_NAME
))
{
/**
* @var $modelForm Form
*/
$modelForm
=
Form
::
find
()
->
where
([
'id'
=>
$formId
])
->
one
();
$model
=
$modelForm
->
createValidateModel
();
if
(
$model
->
load
(
\Yii
::
$app
->
request
->
post
())
&&
$model
->
validate
())
{
$response
[
'success'
]
=
true
;
$response
[
'message'
]
=
'Успешно отправлена'
;
}
return
$response
;
}
}
}
/**
...
...
views/blank-form.php
View file @
2cd58c22
...
...
@@ -12,7 +12,8 @@ use skeeks\modules\cms\form\widgets\ActiveForm;
?>
<?php
$form
=
ActiveForm
::
begin
([
'modelForm'
=>
$model
->
modelForm
,
]);
?>
]);
?>
<?
if
(
$fields
)
:
?>
<?
foreach
(
$fields
as
$formField
)
:
?>
...
...
widgets/ActiveForm.php
View file @
2cd58c22
...
...
@@ -35,4 +35,63 @@ class ActiveForm extends \skeeks\cms\base\widgets\ActiveForm
echo
\yii\helpers\Html
::
hiddenInput
(
Form
::
FROM_PARAM_ID_NAME
,
$this
->
modelForm
->
id
);
}
public
function
run
()
{
parent
::
run
();
$this
->
view
->
registerJs
(
<<<JS
$('#{$this->id}').on('beforeSubmit', function (event, attribute, message) {
return false;
});
$('#{$this->id}').on('afterValidate', function (event, attribute, message) {
var Jform = $(this);
var ajax = sx.ajax.preparePostQuery($(this).attr('action'), $(this).serialize());
new sx.classes.AjaxHandlerBlocker(ajax, {
'wrapper': '#' + $(this).attr('id')
});
//new sx.classes.AjaxHandlerNoLoader(ajax); //отключение глобального загрузчика
new sx.classes.AjaxHandlerNotifyErrors(ajax, {
'error': "Не удалось отправить форму",
}); //отключение глобального загрузчика
ajax.onError(function(e, data)
{
})
.onSuccess(function(e, data)
{
var response = data.response;
if (response.success == true)
{
$('input', Jform).each(function(i,s)
{
if ($(this).attr('name') != '_csrf' && $(this).attr('name') != 'sx-auto-form')
{
$(this).val('');
}
});
sx.notify.success(response.message);
} else
{
sx.notify.error(response.message);
}
})
.execute();
return false;
});
JS
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment