Skip to content

Instantly share code, notes, and snippets.

@morozVA
Last active March 6, 2018 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morozVA/e543848590af94cb267d1ee4748d2e64 to your computer and use it in GitHub Desktop.
Save morozVA/e543848590af94cb267d1ee4748d2e64 to your computer and use it in GitHub Desktop.
evo eForm
<div class="modal fade" id="callBack">
<div class="modal-dialog modal-sm">
<div id="myModal_form">
[!eForm? &formid=`Form` &fromname=`admin@site.by` &from=`admin@site.by` &to=`[[DocInfo? &docid=`2` &field=`send-email`]]` &tpl=`tplForm` &report=`tplReport` &thankyou=`tplThank` &subject=`Заказ звонка с сайта [(site_name)]`!]
</div>
</div>
</div>
tplForm
<form method="post" action="[~[*id*]~]" name="Form" id="Form" class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<div class="h4 modal-title">Обратный звонок</div>
</div>
<div class="modal-body">
<input value="" name="special" class="special" type="text" eform="Спец:date:0" style="display:none;">
<input class="form-control" type="text" name="name" placeholder="Ваше имя" eform="Ваше имя:string:1">
<input class="form-control" type="text" name="phone" placeholder="Ваш телефон" eform="Ваш телефон:string:1">
<input type="text" class="hidden" name="page" value="[~[*id*]~]">
</div>
<div class="validationmessage">[+validationmessage+]</div>
<div class="modal-footer">
<input type="submit" class="btn" name="submit" id="submit" value=" Отправить ">
</div>
</form>
tplReport
<div>Заказ звонка с сайта [(site_name)]</div>
<div>Имя: [+name+]</div>
<div>Телефон: [+phone+]</div>
<div>Страница: [+page+]</div>
tplThank
<div class="email_sended">Ваше сообщение отправлено.</div>
jQuery(function(){
jQuery(document).on("submit","#Form",function(e){
e.preventDefault();
var m_method=jQuery(this).attr('method');
var m_action=jQuery(this).attr('action');
var m_data=jQuery(this).serialize();
jQuery.ajax({
type: m_method,
url: m_action,
data: m_data,
resetForm: 'true',
success: function(result){
var data = jQuery(result).find("#myModal_form").html();
jQuery("#myModal_form").html(data);
}
});
});
});
<form method="post" action="[~[*id*]~]" name="myform" enctype="multipart/form-data">
<input type="file" id="file" name="file" eform="Attachment:file:0" />
[+file+]
var consult_form = $('#consult_form .email_sended').text();
if(consult_form == 'Ваш вопрос отправлен.'){
$('#modalQuestion').modal('show');
}
var consult_form2 = $('#consult_form .errors').length;
if(consult_form2 == 1){
$('#modalQuestion').modal('show');
}
[!validatefilesize!]
&eFormOnValidate=`validatefilesize`
<?php
function validatefilesize($fields,&$vMsg,&$rMsg){
if ($_FILES['file']['size'] > 5000000){ //имя поля и максимальный размер файла
$vMsg[]='Размер файла больше допустимого';
}
return;
};
динамические опшены в селекте выдавали ошибку "Неверное значение". Вот костыль - вставляем в скрытый инпут выбранное в селекте значение, селект удаляем.
<form method="post" action="[~[*id*]~]" name="Form" id="Form" onsubmit="$('#shop').val($('#shop_select').val()); $('#shop_select').remove()">
/***************Отправка файла клиенту после заполнения формы*****************/
чанк {{forma1}}
[!sendPrice!]
[!eForm? &formid=`form1` &to=`ВАШ МЕЙЛ` &tpl=`form_tpl1` &report=`formreport` &thankyou=`thank-tpl` &subject=`ТЕМА ПИСЬМА` &eFormOnMailSent=`sendPrice`!]
чанк form_tpl1
<div id="forma">
[+validationmessage+]
<form method="post" action="[~[*id*]~]" name="myform" enctype="multipart/form-data">
<input type="hidden" name="formid" value="form1" />
<input type="text" name="io" size="40" maxlength="60" placeholder="Имя" eform="Имя::0" />
<input type="text" name="email" size="40" maxlength="40" placeholder="email" eform="Ваш email:email:0" />
<textarea cols="32" rows="3" name="content" placeholder="Текст" eform="Текст письма:html:1"></textarea>
<input type="submit" class="findoutmore" name="submit" value="Отправить" ></form></div>
formreport
<table><tr><td>Name:</td><td>[+io+]</td></tr>
<tr ><td>Email:</td><td>[+email+]</td></tr>
<tr ><td>Текст сообщения:</td><td>[+content+]</td></tr></table>
сниппет sendPrice
<?php
function sendPrice(&$fields) {
global $modx;
$txt = $modx->getChunk('priceSubmitTpl'); // шаблон письма, при желании можно поменять на parceChunk и использовать плейсхолдеры
$curEmail=$fields['email']; // поле с емейлом
$tvvallist = $modx->getTemplateVarOutput(array("priceFile"), 144); // TV параметр, в котором можно выбирать отправляемый файл
$attachFile = realpath('./'.$tvvallist['priceFile']);
$MailErrors=array();
include_once "manager/includes/controls/class.phpmailer.php";
$mailer = new PHPMailer();
$mailer->CharSet='utf-8';
$mailer->IsHTML(true);
$mailer->From =$modx->config['emailsender'];
$mailer->FromName='Название сайта отправителя';
$mailer->Subject ='Тема письма';
$mailer->Body = $txt;
$mailer->AddAddress($curEmail);
$mailer->AddAttachment($attachFile);
if (!$mailer->Send())
$MailErrors[$curEmail]=$mailer->ErrorInfo;
return true;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment