Last active
August 31, 2019 20:30
-
-
Save TrywaR/afaa297fa50f1540c3e766a535ab8cd9 to your computer and use it in GitHub Desktop.
MODX Revo | PhoneGap > Отправка сообщения на сервер | Отправка сообщения из приложения сделанного на PhoneGap или Cordova на сайт с MODX Revo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[-Вывод и работа формы при помощи плагина formit в Modx Revo, где form_app_tpl чанк с самой формой]] | |
[[!FormIt? | |
&emailTpl=`form_app_tpl` | |
&formName=`Форма из приложения` | |
&hooks=`FormItSaveForm, email` | |
&emailSubject=`[[++site_name]]: Форма из приложения` | |
&emailTo=`example@email.com` | |
&emailFrom=`info@site.ru` | |
&frontend_css=`` | |
]] | |
[[!+fi.successMessage:is=``:then=` | |
[[$form_app_tpl]] | |
`:else=` | |
<p>Сообщение успешно отправленно</p> | |
`]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
// js для отправки формы на сервер и получения результата | |
// post | |
// - contact_form | |
$(document).on('submit', '#contact_form', function(data){ | |
$(this).addClass('_load_') | |
// - Проверка валидации Html 5 | |
if($("form")[0].checkValidity()) { | |
// --- Отправка | |
$.ajax({ | |
url: [адрес страницы с формой], | |
data: $(this).serialize(), | |
type: "POST", | |
xhrFields: { | |
withCredentials: false | |
} | |
}).done(function(data) { | |
// ---- Приём | |
$(this).removeClass('_load_') | |
$(this).addClass('_done_') | |
$(this).html(data) | |
}) | |
return false | |
} | |
else{ | |
// -- Ошибка валидации | |
} | |
}) | |
// - contact_form x | |
// post x | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Плагин для MODX Revo чтобы обрабатывать запросы со сторонних платформ | |
// Должно быть включено системное событие OnWebPageInit, если летит POST или GET c app разрешаем обработку | |
<?php | |
if(isset($_REQUEST['app'])) | |
header('Access-Control-Allow-Origin: *'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment