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

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

[[!FormIt?
   &hooks=`spam, MailChimpSubscribe`
   &validate=`nospam:blank,
      email:email:required,
      newsgroup:required`
   &successMessage=`Thank you! Please check your inbox to verify your subscription.`
   &submitVar=`mailchimpSubmit`
   &mailchimpListId=`##########`
   &mailchimpFields=`email=EMAIL,name=FNAME`
   &mailchimpSubscribeField=`newsgroup`
]]


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

   <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="[[!+fi.email]]" required />
   <button type="submit" name="mailchimpSubmit">Subscribe</button>
</form>

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
Janice

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.

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

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:

<form>
   ...  
   <input type="hidden" name="mailchimpSubmit" value="not empty" />
   <button type="submit">Subscribe</button>
</form>
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”.