SOLVED::mailchimpSubscribe can't get it to work using &submitVar?

I can’t get the mailchimpSubscribe extra to work when I use &submitVar but otherwise it works as expected.
My code with &submitVar is:

   &hooks=`spam, MailChimpSubscribe`
   &successMessage=`Thank you! Please check your inbox to verify your subscription.`

<form id="newsletter" action="[[~[[*id]]]]#newsletter" method="post">   
   [[!+fi.successMessage:notempty=`<p class="success">[[!+fi.successMessage]]</p>`]]

   <input type="hidden" name="nospam" value="" />
   <input type="hidden" name="newsgroup" value="yes" />
   <input type="hidden" name="name" value="" />
   <input type="hidden" name="mailchimpSubmit" value="" />
   <input type="email" name="email" id="email" placeholder="Email address" value="[[!]]" required />
   <button type="submit" name="mailchimpSubmit">Subscribe</button>

Can anyone help or provide a working form that uses &submitVar?
I’m using the latest version of Modx and all extras are up to date.
Thanks for any help

Does changing the sequence and moving submitVar=`mailchimpSubmit` to the end (after &mailchimpSubscribeField=`newsgroup`) make any difference?

Having two fields with the same name is probably not a good idea.

   <input type="hidden" name="mailchimpSubmit" value="" />
   <button type="submit" name="mailchimpSubmit">Subscribe</button>

Also, according to the documentation “Multiple forms should be used with INPUT type=“submit” […] button elements have been reported not working.”
I believe you can use a hidden field instead, but the value attribute can’t be empty.

In summary, try this instead:

   <input type="hidden" name="mailchimpSubmit" value="not empty" />
   <button type="submit">Subscribe</button>
1 Like

@halftrainedharry - Thank you!! That is indeed how it’s meant to be written. I’d seen the threads about having a hidden input but had not realised it should not appear on the button tag also.

Thanks again

Side-node: it is possible to put it on the button, but you have to give it a value: <button type="submit" name="mailchimpSubmit" value="1">. With that, you can have multiple submit buttons with a different name that each trigger a different FormIt for processing. Fun stuff. :wink:

(Side-note to the side-note: when using multiple buttons there’s some special logic as to which button gets “pressed” and thus which value gets submitted. Typically it’s the first type=“submit” button. If enhancing a form with AJAX, you’ll need to take extra care to get submit button values as they wont be in a serialized form by default iirc.)

For simple single-action form, hidden input with matching name and any non-empty value is simplest.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.