Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process mailchimp forms based on class name instead of id #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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);
});
}
});
}
});
});