Skip to content

Commit e70811b

Browse files
authored
Merge pull request #173 from mailchimp/enhancement/172
Allow multiple Mailchimp forms on a single page.
2 parents 202bfea + 1e79368 commit e70811b

22 files changed

+277
-251
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ If you are upgrading to version 1.6.0, you will need to updated any references t
7373

7474
## Frequently Asked Questions
7575

76-
### Can I have multiple forms on one page?
77-
78-
No, only one form should exist per page, no matter the display type (block, widget, or shortcode).
79-
8076
### Why am I not seeing all my fields in my form?
8177

8278
You need to ensure that the fields are enabled both in your Mailchimp account (Audience > Signup forms) and in the settings of this plugin. Once the fields are enabled in both places, then they'll appear in the editor and frontend of your site.

assets/css/frontend.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
div.mc_interest{
1010
width:100%;
1111
}
12-
#mc_signup_form label.mc_interest_label {
12+
.mc_signup_form label.mc_interest_label {
1313
display:inline;
1414
}
1515
.mc_signup_submit {
@@ -35,7 +35,7 @@ ul.mc_list li {
3535
margin-bottom: 0.75em;
3636
}
3737
.mc_custom_border_hdr,
38-
#mc_subheader {
38+
.mc_subheader {
3939
line-height: 1.25em;
4040
margin-bottom: 18px;
4141
}
@@ -86,15 +86,15 @@ select.mc_select {
8686
.mc_interest input {
8787
margin-bottom: 0.4em;
8888
}
89-
#mc_signup_submit {
89+
.mc_signup_submit_button {
9090
margin-top: 1.5em;
9191
padding: 10px 8px;
9292
width: 80%;
9393
}
94-
#mc_unsub_link a {
94+
.mc_unsub_link a {
9595
font-size: 0.75em;
9696
}
97-
#mc_unsub_link {
97+
.mc_unsub_link {
9898
margin-top: 1.0em;
9999
}
100100
.mc_header_address,
@@ -110,7 +110,7 @@ select.mc_select {
110110
.mc_email_type {
111111
padding-left: 4px;
112112
}
113-
#mc-indicates-required {
113+
.mc-indicates-required {
114114
width:100%;
115115
margin-top: 1em;
116116
}

includes/blocks/mailchimp/block.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
},
4747
"supports": {
4848
"html": false,
49-
"multiple": false,
5049
"reusable": true,
5150
"align": [ "wide", "full" ],
5251
"__experimentalBorder": {

includes/blocks/mailchimp/edit.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@ export const BlockEdit = (props) => {
328328
value={header}
329329
onChange={(header) => setAttributes({ header })}
330330
/>
331-
<div id="mc_signup">
332-
<div id="mc_signup_form">
333-
<div id="mc_subheader">
331+
<div className="mc_signup">
332+
<div className="mc_signup_form">
333+
<div className="mc_subheader">
334334
<RichText
335335
className="mailchimp-block__sub-header"
336336
tagName="h3"
@@ -359,7 +359,7 @@ export const BlockEdit = (props) => {
359359
templateLock="insert"
360360
/>
361361
{show_required_indicator && (
362-
<div id="mc-indicates-required">
362+
<div className="mc-indicates-required">
363363
<RichText
364364
tagName="span"
365365
value={required_indicator_text}
@@ -372,8 +372,7 @@ export const BlockEdit = (props) => {
372372
)}
373373
<div className="mc_signup_submit">
374374
<RichText
375-
id="mc_signup_submit"
376-
className="button"
375+
className="mc_signup_submit_button button"
377376
tagName="button"
378377
placeholder={__('Enter button text.', 'mailchimp')}
379378
value={submit_text}
@@ -383,7 +382,7 @@ export const BlockEdit = (props) => {
383382
/>
384383
</div>
385384
{!!show_unsubscribe_link && (
386-
<div id="mc_unsub_link">
385+
<div className="mc_unsub_link">
387386
<RichText
388387
tagName="a"
389388
value={unsubscribe_link_text}

includes/blocks/mailchimp/editor.css

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
div.mc_interest{
33
width:100%;
44
}
5-
#mc_signup_form label.mc_interest_label {
5+
.mc_signup_form label.mc_interest_label {
66
display:inline;
77
}
88
.mc_signup_submit {
@@ -17,7 +17,7 @@ ul.mc_list li {
1717
font-size: 14px;
1818
}
1919

20-
#mc_message {
20+
.mc_message_wrapper {
2121
display: none;
2222
}
2323

@@ -44,37 +44,32 @@ ul.mc_list li {
4444
}
4545

4646
h2.mailchimp-block__header:has(span:empty),
47-
div#mc_subheader:has(h3 span:empty) {
47+
div.mc_subheader:has(h3 span:empty) {
4848
display: none;
4949
}
5050

51-
.wp-block-mailchimp-mailchimp.is-selected div#mc_subheader:has(h3 span:empty),
52-
.wp-block-mailchimp-mailchimp.has-child-selected div#mc_subheader:has(h3 span:empty),
51+
.wp-block-mailchimp-mailchimp.is-selected div.mc_subheader:has(h3 span:empty),
52+
.wp-block-mailchimp-mailchimp.has-child-selected div.mc_subheader:has(h3 span:empty),
5353
.wp-block-mailchimp-mailchimp.is-selected h2.mailchimp-block__header:has(span:empty),
5454
.wp-block-mailchimp-mailchimp.has-child-selected h2.mailchimp-block__header:has(span:empty) {
5555
display: block;
5656
}
5757

58-
#mc_signup_form .mailchimp_merge_field_hidden .mc_var_label,
59-
#mc_signup_form .mailchimp_interest_group_hidden .mc_interests_header {
58+
.mc_signup_form .mailchimp_merge_field_hidden .mc_var_label,
59+
.mc_signup_form .mailchimp_interest_group_hidden .mc_interests_header {
6060
padding: 0.25em 0.5em;
6161
margin: 0px;
6262
}
6363

64-
#mc_subheader {
64+
.mc_subheader {
6565
line-height: 1.25em;
6666
margin-bottom: 18px;
6767
}
6868

69-
#mc_signup_submit {
70-
margin-top: 1.5em;
71-
padding: 10px 8px;
72-
width: 80%;
73-
}
74-
#mc_unsub_link a {
69+
.mc_unsub_link a {
7570
font-size: 0.75em;
7671
}
77-
#mc_unsub_link {
72+
.mc_unsub_link {
7873
margin-top: 1.0em;
7974
text-align: center;
8075
}
@@ -123,17 +118,12 @@ select.mc_select {
123118
.mc_interest input {
124119
margin-bottom: 0.4em;
125120
}
126-
#mc_signup_submit {
121+
.mc_signup_submit_button {
127122
margin-top: 1.5em;
128123
padding: 10px 8px;
129124
width: 80%;
130125
}
131-
#mc_unsub_link a {
132-
font-size: 0.75em;
133-
}
134-
#mc_unsub_link {
135-
margin-top: 1.0em;
136-
}
126+
137127
.mc_header_address,
138128
.mc_email_format {
139129
display: block;
@@ -147,7 +137,7 @@ select.mc_select {
147137
.mc_email_type {
148138
padding-left: 4px;
149139
}
150-
#mc-indicates-required {
140+
.mc-indicates-required {
151141
width:100%;
152142
margin-top: 1em;
153143
}

includes/blocks/mailchimp/markup.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
?>
1414
<div <?php echo get_block_wrapper_attributes(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
1515
<?php
16-
1716
// Backwards compatibility for old block, which didn't have innerBlocks.
1817
$block_instance = $block->parsed_block;
1918
$inner_blocks = $block_instance['innerBlocks'] ?? [];
@@ -27,6 +26,7 @@
2726

2827
// Make sure we have a list ID and it's valid.
2928
$list_id = $attributes['list_id'] ?? '';
29+
$form_id = wp_unique_id( $list_id . '_' );
3030
$lists = ( new Mailchimp_List_Subscribe_Form_Blocks() )->get_lists();
3131
$list_ids = array_map(
3232
function ( $single_list ) {
@@ -96,17 +96,17 @@ function ( $single_list ) {
9696
}
9797
if ( $sub_heading ) {
9898
?>
99-
<div id="mc_subheader">
99+
<div class="mc_subheader">
100100
<h3>
101101
<?php echo wp_kses_post( $sub_heading ); ?>
102102
</h3>
103103
</div><!-- /mc_subheader -->
104104
<?php
105105
}
106106
?>
107-
<div id="mc_signup">
108-
<form method="post" action="#mc_signup" id="mc_signup_form" class="mc_signup_form">
109-
<input type="hidden" id="mc_submit_type" class="mc_submit_type" name="mc_submit_type" value="html" />
107+
<div id="mc_signup_<?php echo esc_attr( $form_id ); ?>">
108+
<form method="post" action="#mc_signup_<?php echo esc_attr( $form_id ); ?>" id="mc_signup_form_<?php echo esc_attr( $form_id ); ?>" class="mc_signup_form">
109+
<input type="hidden" class="mc_submit_type" name="mc_submit_type" value="html" />
110110
<input type="hidden" name="mcsf_action" value="mc_submit_signup_form" />
111111
<input type="hidden" name="mailchimp_sf_list_id" value="<?php echo esc_attr( $list_id ); ?>" />
112112
<input type="hidden" name="mailchimp_sf_update_existing_subscribers" value="<?php echo esc_attr( $update_existing_subscribers ); ?>" />
@@ -117,7 +117,7 @@ function ( $single_list ) {
117117
wp_nonce_field( 'mc_submit_signup_form', '_mc_submit_signup_form_nonce', false );
118118
?>
119119
<div class="mc_form_inside">
120-
<div class="mc_message_wrapper" id="mc_message">
120+
<div class="mc_message_wrapper">
121121
<?php echo wp_kses_post( mailchimp_sf_global_msg() ); ?>
122122
</div>
123123

@@ -136,7 +136,7 @@ function ( $single_list ) {
136136
// Show an explanation of the * if there's more than one field
137137
if ( $show_required_indicator ) {
138138
?>
139-
<div id="mc-indicates-required">
139+
<div class="mc-indicates-required">
140140
<?php echo esc_html( $required_indicator_text ); ?>
141141
</div><!-- /mc-indicates-required -->
142142
<?php
@@ -146,7 +146,7 @@ function ( $single_list ) {
146146
mailchimp_sf_honeypot_field();
147147
?>
148148
<div class="mc_signup_submit">
149-
<input type="submit" name="mc_signup_submit" class="mc_signup_submit_button" id="mc_signup_submit" value="<?php echo esc_attr( $submit_text ); ?>" class="button" />
149+
<input type="submit" name="mc_signup_submit" class="mc_signup_submit_button" id="mc_signup_submit_<?php echo esc_attr( $form_id ); ?>" value="<?php echo esc_attr( $submit_text ); ?>" class="button" />
150150
</div><!-- /mc_signup_submit -->
151151

152152
<?php
@@ -155,7 +155,7 @@ function ( $single_list ) {
155155
$api = mailchimp_sf_get_api();
156156
$host = 'https://' . $api->datacenter . '.list-manage.com';
157157
?>
158-
<div id="mc_unsub_link" align="center">
158+
<div class="mc_unsub_link" align="center">
159159
<a href="<?php echo esc_url( $host . '/unsubscribe/?u=' . $user['account_id'] . '&amp;id=' . $list_id ); ?>" target="_blank">
160160
<?php echo esc_html( $unsubscribe_link_text ); ?>
161161
</a>

mailchimp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function mailchimp_sf_load_resources() {
192192
function mailchimp_sf_custom_style_css() {
193193
ob_start();
194194
?>
195-
#mc_signup_form {
195+
.mc_signup_form {
196196
padding:5px;
197197
border-width: <?php echo absint( get_option( 'mc_form_border_width' ) ); ?>px;
198198
border-style: <?php echo ( get_option( 'mc_form_border_width' ) === 0 ) ? 'none' : 'solid'; ?>;

0 commit comments

Comments
 (0)