Title: [Plugin: MailChimp Widget] subscribe form on page using shortcode
Last modified: August 19, 2016

---

# [Plugin: MailChimp Widget] subscribe form on page using shortcode

 *  Resolved [duncanmoo](https://wordpress.org/support/users/duncanmoo/)
 * (@duncanmoo)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/)
 * Hi
 * I am trying to display the widget on a page (also using it on the sidebar elsewhere
   too), using the_widget().
 * The code below gives me an input form and empty submit button and probably posts
   to no actual list.
 *     ```
       <?php
       function chimplocals() {
       	//return "testing";
       	ob_start();
       		the_widget('NS_Widget_MailChimp');
       		$output = ob_get_contents();
           ob_end_clean();
           return $output;
       }
       add_shortcode('chimplocals', 'chimplocals');
       ?>
       ```
   
 * WordPress function definition says
    `the_widget($widget, $instance, $args);` 
   can you help with what the instance and args should be to call this?
 * Is there a better way to do what I am trying to do?
 * Thanks
 * [http://wordpress.org/extend/plugins/mailchimp-widget/](http://wordpress.org/extend/plugins/mailchimp-widget/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [jameslafferty](https://wordpress.org/support/users/jameslafferty/)
 * (@jameslafferty)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053001)
 * Duncanmoo,
 * This is the function you want to look at to get the instance variables:
 *     ```
       public function update ($new_instance, $old_instance) {
   
       		$instance = $old_instance;
   
       		$instance['collect_first'] = ! empty($new_instance['collect_first']);
   
       		$instance['collect_last'] = ! empty($new_instance['collect_last']);
   
       		$instance['current_mailing_list'] = esc_attr($new_instance['current_mailing_list']);
   
       		$instance['failure_message'] = esc_attr($new_instance['failure_message']);
   
       		$instance['signup_text'] = esc_attr($new_instance['signup_text']);
   
       		$instance['success_message'] = esc_attr($new_instance['success_message']);
   
       		$instance['title'] = esc_attr($new_instance['title']);
   
       		return $instance;
   
       	}
       ```
   
 * The arguments get set up in your sidebar, the before_widget, after_widget, before_title,
   after_title stuff. Does that get you pointed in the right direction?
 * Cheers,
 * James
 *  Thread Starter [duncanmoo](https://wordpress.org/support/users/duncanmoo/)
 * (@duncanmoo)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053008)
 * Thanks James
 * This gets me closer, but not quite there yet, my shortcode now looks like this:
 *     ```
       // [chimpsubs letter=locals]
       function chimpsubs($atts) {
       	extract(shortcode_atts(array(
       	      'letter' => 'xyz123456'
            ), $atts));
   
       	ob_start();
       		the_widget('NS_Widget_MailChimp',array('signup_text'=>'subscribe',
       											   'current_mailing_list'=>$letter,
       											   'failure_message'=>'There was a problem processing your submission.',
       											   'success_message'=>'Thank you for joining our mailing list. Please check your email for a confirmation link.'));
       		$output = ob_get_contents();
           ob_end_clean();
           return $output;
       }
       add_shortcode('chimpsubs', 'chimpsubs');
       ```
   
 * Form displays nicely but submission says “Sorry, but that does not look like 
   an email address to me.” for perfectly valid addresses (ones that do work on 
   the sidebar).
    Noticed a variable on sidebar HTML: `<input type="hidden" value
   ="3" name="ns_mc_number">` which on my custom implementation displays as: `<input
   type="hidden" value="-1" name="ns_mc_number">`
 * The full HTML of a call to the shortcode:
 *     ```
       <div class="widget widget_ns_mailchimp">
       	<h2 class="widgettitle"></h2>
       	<form method="post" id="ns_widget_mailchimp_form--1" action="/newsletter/">
       		<div class="error"></div>
       		<label>Email Address :</label>
       		<input type="hidden" value="-1" name="ns_mc_number">
       		<input type="text" name="ns_widget_mailchimp_email">
       		<input type="submit" value="subscribe" name="subscribe" class="button">
       	</form>
       	<script type="text/javascript">
       	jQuery('#ns_widget_mailchimp_form--1').ns_mc_widget({"url" : "/index.php", "cookie_id" : "ns_widget_mailchimp--1", "cookie_value" : "hidden hash", "loader_graphic" : "http://website.localhost/wp-content/plugins/mailchimp-widget/images/ajax-loader.gif"});
       	</script>
       </div>
       ```
   
 * What am I missing?
 *  Plugin Author [jameslafferty](https://wordpress.org/support/users/jameslafferty/)
 * (@jameslafferty)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053050)
 * Hi Duncanmoo,
 * So the issue is that the plugin submits back to the correct MailChimp list based
   on which instance of the widget is being used. I thought perhaps there might 
   be a way to workaround this, but, alas, there is nothing that can be done without
   considerable acrobatics. This has come up a few times, and when I get some time
   to work on the next release of the plugin, that’s definitely a feature I’d like
   to incorporate. If you’re interested, the line of code where that -1 is coming
   from is here:
 *     ```
       $widget_obj->_set(-1);
       $widget_obj->widget($args, $instance);
       ```
   
 * which is the last two lines of the_widget() on ll 1206-1207 of wp-includes/widgets.
   php. That makes a widget you instantiate with the_widget very different from 
   widgets made in the normal way.
 * Sorry I couldn’t be of more help right away, and I’ll post back here when I release
   a version that does what you want.
 * Cheers,
 * James
 *  Thread Starter [duncanmoo](https://wordpress.org/support/users/duncanmoo/)
 * (@duncanmoo)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053052)
 * Thanks James and no need to apologize, I really appreciate you getting back to
   me on this. It does let anyone out there know that for now the widget can not
   be called other than through using the WP widget interface.
 *  [catriona](https://wordpress.org/support/users/catriona/)
 * (@catriona)
 * [15 years ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053091)
 * Hi Duncanmoo,
 * I was wrestling with the same issue (I think), in that I wanted to display the
   widget only on certain pages.
 * Here is my somewhat roundabout solution. It’s a wee bit wacky hacky feeling, 
   and the MailChimp javascript file will still be called on all your public pages,
   but I figure this is good enough for now!
 * 1) Created a special widget area just for this guy in functions.php. If you have
   unused widget areas, you could just use one of those.
 *     ```
       register_sidebar( array(
           'id'          => 'mailchimp',
           'name'        => __( 'Mailchimp', 'synotac' ),
           'description' => __( 'Mailchimp widget.', 'synotac' ),
       ) );
       ```
   
 * 2) Add the widget in the wordpress admin area to my new sidebar
 * 3) Only call that sidebar when I want it to display (page.php, single.php, special
   sidebar times, etc.). You could probably do away with the is_active check if 
   you’re feeling bold. And remember that it needs it’s unordered (ul) list.
 *     ```
       <?php
         if ( is_active_sidebar( 'mailchimp' ) ) {
           dynamic_sidebar( 'mailchimp' );
         }
       ?>
       ```
   
 * Hope that helps!
 * And many thanks to James for the plugin! I like it!
    Cat
 *  Plugin Author [jameslafferty](https://wordpress.org/support/users/jameslafferty/)
 * (@jameslafferty)
 * [15 years ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053092)
 * Hi Cat,
 * Nice workaround. Using before_widget and after_widget in the register sidebar
   call will allow you to put the widget markup in whatever container you’d like:
 *     ```
       register_sidebar( array(
           'id'          => 'mailchimp',
           'name'        => __( 'Mailchimp', 'synotac' ),
           'description' => __( 'Mailchimp widget.', 'synotac' ),
       ) );
       ```
   
 * in your code could become
 *     ```
       register_sidebar( array(
           'id'          => 'mailchimp',
           'name'        => __( 'Mailchimp', 'synotac' ),
           'description' => __( 'Mailchimp widget.', 'synotac' ),
           'before_widget' => '<div id="%1$s" class="widget %2$s">',
           'after_widget' => '</div>',
       ) );
       ```
   
 * if you wanted to use a div to contain the widget. Thanks so much for trying out
   the plugin, and I’m glad you like it. 🙂
 *  [Deepak](https://wordpress.org/support/users/maverics1luv/)
 * (@maverics1luv)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053115)
 * [mailchimpsf_widget]
 * i think you want this.
 * you can put it in you template file as:
 * <?php do_shortcode(‘[mailchimpsf_widget]’); ?>
 * for more details you can contact me @ [dpkmahendru@gmail.com](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/dpkmahendru@gmail.com?output_format=md)
 *  Plugin Author [jameslafferty](https://wordpress.org/support/users/jameslafferty/)
 * (@jameslafferty)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053116)
 * Hi maverics1luv,
 * It looks to me like that’s a different plugin. Which plugin are you using?
 * Cheers,
 * J.
 *  [Deepak](https://wordpress.org/support/users/maverics1luv/)
 * (@maverics1luv)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053117)
 * Hi James,
 * I am using this one, Please check it out:
    [http://wordpress.org/extend/plugins/mailchimp/](http://wordpress.org/extend/plugins/mailchimp/)
 * & shortcode is above mentioned to use it in the page.
 * Regards

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘[Plugin: MailChimp Widget] subscribe form on page using shortcode’ is
closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/mailchimp-widget.svg)
 * [MailChimp Widget](https://wordpress.org/plugins/mailchimp-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mailchimp-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mailchimp-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/mailchimp-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mailchimp-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mailchimp-widget/reviews/)

 * 9 replies
 * 4 participants
 * Last reply from: [Deepak](https://wordpress.org/support/users/maverics1luv/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/plugin-mailchimp-widget-subscribe-form-on-page-using-shortcode/#post-2053117)
 * Status: resolved