Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Resources/Private/Templates/Form/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
<f:layout name="General"/>

<f:section name="content">
<f:form object="{form}" action="response" name="form" id="mailchimp-form" class="form-horizontal"
<f:form object="{form}" action="response" name="form" class="form-horizontal mailchimp-form"
data="{url:'{f:render(section:\'formUrl\') -> f:spaceless() -> f:format.htmlentitiesDecode()}'}">
<f:form.validationResults>
<f:if condition="{validationResults.flattenedErrors}">
<ul class="errors">
<f:for each="{validationResults.flattenedErrors}" as="errors" key="propertyPath">

<f:for each="{errors}" as="error">
<li>
<f:translate key="error.{propertyPath}.{error.code}"
Expand Down Expand Up @@ -66,7 +65,7 @@
<mc:footerData>
<script type="text/javascript" src="{f:uri.resource(path:'JavaScript/mailchimp.js')}"></script>
</mc:footerData>
<div id="mailchimp-ajax-response"></div>
<div class="mailchimp-ajax-response"></div>
</f:form>
</f:section>

Expand Down
39 changes: 22 additions & 17 deletions Resources/Public/JavaScript/mailchimp.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
$(function () {
let $extMailchimpForms = $('form.mailchimp-form');

$(document).on('submit', '#mailchimp-form', function (e) {
'use strict';
if ($extMailchimpForms.length) {

let $this = $(this),
url = $this.data('url');
$extMailchimpForms.on('submit', function (e) {

if (url) {
e.preventDefault();
let $this = $(this),
url = $this.data('url');

$.ajax({
type: 'POST',
url: url,
data: $this.serialize(),
dataType: 'html',
encode: false
})
.done(function (data) {
$('#mailchimp-ajax-response').html(data);
});
if (url) {
e.preventDefault();

$.ajax({
type: 'POST',
url: url,
data: $this.serialize(),
dataType: 'html',
encode: false
})
.done(function (data) {
$('.mailchimp-ajax-response', $this).html(data);
});
}
});
}
});
});