I want to be able to change the title of the submit button of the Mailchimp block when someone subscribes or unsubscribes to mail chimp list. I'm using mailchimp block on D7. How shall I do it?


As mentioned, you'll want to use hook_form_alter(). You can check if the user has subscribed with mailchimp_is_subscribed() and change the submit button text accordingly.

 * Implements hook_form_alter().
function my_module_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'mailchimp_lists_user_subscribe_form_test') {
    global $user;
    // First parameter is the list id, which can be found here:
    // https://polkaspots.zendesk.com/hc/en-us/articles/201070513-Where-can-I-find-my-MailChimp-API-key-and-List-ID
    $form['submit']['#value'] = mailchimp_is_subscribed('123abc', $user->mail) ? t('Unregister') : t('Register');

enter image description here

| improve this answer | |
  • Do you have a short code example of how you might do that? – rooby May 10 '15 at 3:30
  • Sure, hope it helps! Cheers – superdrupal May 10 '15 at 11:15

You could use the hook_form_alter() hook or install the string overrides module if you don't wish to write any code.

| improve this answer | |
  • I want to change it after submitting the form. The title right now is register so when someone registers i want it to get changed to unregister. – lameei Feb 10 '14 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.