Skip to content

Commit fb2b4b8

Browse files
authored
Merge pull request #40 from mailchimp/fix/invalid-list
Show an error message and return early if no list is chosen
2 parents 225f432 + 06b96e5 commit fb2b4b8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

mailchimp.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,16 @@ function mailchimp_sf_save_general_form_settings() {
630630
* Sees if the user changed the list, and updates options accordingly
631631
**/
632632
function mailchimp_sf_change_list_if_necessary() {
633+
if ( ! isset( $_POST['mc_list_id'] ) ) {
634+
return;
635+
}
636+
637+
if ( empty( $_POST['mc_list_id'] ) ) {
638+
$msg = '<p class="error_msg">' . esc_html__( 'Please choose a valid list', 'mailchimp' ) . '</p>';
639+
mailchimp_sf_global_msg( $msg );
640+
return;
641+
}
642+
633643
// Simple permission check before going through all this
634644
if ( ! current_user_can( MCSF_CAP_THRESHOLD ) ) { return; }
635645

@@ -645,7 +655,7 @@ function mailchimp_sf_change_list_if_necessary() {
645655

646656
$lists = $lists['lists'];
647657

648-
if ( is_array( $lists ) && ! empty( $lists ) && isset( $_POST['mc_list_id'] ) ) {
658+
if ( is_array( $lists ) && ! empty( $lists ) ) {
649659

650660
/**
651661
* If our incoming list ID (the one chosen in the select dropdown)

views/setup_page.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<p class="mc-p"><?php esc_html_e( 'Please select the Mailchimp list you\'d like to connect to your form.', 'mailchimp' ); ?></p>
125125
<p class="mc-list-note"><strong><?php esc_html_e( 'Note:', 'mailchimp' ); ?></strong> <?php esc_html_e( 'Updating your list will not remove list settings in this plugin, but changing lists will.', 'mailchimp' ); ?></p>
126126

127-
<form method="post" action="options-general.php?page=mailchimp_sf_options">
127+
<form method="post" action="<?php echo esc_url( add_query_arg( array( 'page' => 'mailchimp_sf_options' ), admin_url( 'admin.php' ) ) ); ?>">
128128
<?php
129129
// we *could* support paging, but few users have that many lists (and shouldn't)
130130
$lists = $api->get( 'lists', 100, array( 'fields' => 'lists.id,lists.name,lists.email_type_option' ) );
@@ -179,7 +179,7 @@
179179
?>
180180

181181
<p class="submit">
182-
<form method="post" action="options-general.php?page=mailchimp_sf_options">
182+
<form method="post" action="<?php echo esc_url( add_query_arg( array( 'page' => 'mailchimp_sf_options' ), admin_url( 'admin.php' ) ) ); ?>">
183183
<input type="hidden" name="mcsf_action" value="reset_list" />
184184
<input type="submit" name="reset_list" value="<?php esc_attr_e( 'Reset List Options and Select again', 'mailchimp' ); ?>" class="button" />
185185
<?php wp_nonce_field( 'reset_mailchimp_list', '_mcsf_nonce_action' ); ?>
@@ -200,7 +200,7 @@
200200
?>
201201

202202
<div>
203-
<form method="post" action="options-general.php?page=mailchimp_sf_options">
203+
<form method="post" action="<?php echo esc_url( add_query_arg( array( 'page' => 'mailchimp_sf_options' ), admin_url( 'admin.php' ) ) ); ?>">
204204
<div class="mc-section">
205205
<input type="hidden" name="mcsf_action" value="change_form_settings">
206206
<?php wp_nonce_field( 'update_general_form_settings', '_mcsf_nonce_action' ); ?>

0 commit comments

Comments
 (0)