Checkbox on Login Form

Jason Ruyle - May 4, 2009 - 19:58
Project:Simplenews
Version:6.x-1.0-rc6
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Anyone know a way to add the checkbox to opt-in to the login form?

I've tried adding:

<?php
 
if ($form_id == 'user_login') {

    global
$user;

   
$form['simplenews'] = array(
     
'#title' => t(''),
     
'#description' => t('Sign me up for the club'),
     
'#weight' => 4,
    );
   
   
$form['simplenews']['simplenews-55'] = array(
     
'#title' => t(''),
     
'#type' => 'checkbox',
     
'#description' => 'Sign me up for club',
     
'#default_value' => 1,
     
'#attributes' => array(
       
'tabindex' => 3,
      ),
    );

    return;
  }
?>

It adds the option to signup with a place for checkbox, but doesn't add the user to that specific newsletter. Anyone have a suggestion?

#1

adamo - June 7, 2009 - 16:37

There's a module that does this: http://drupal.org/project/simplenews_register.

If you were to do it in your own form you would need to create a #submit callback function and have it execute simplenews_subscribe_user:

<?php
simplenews_subscribe_user
($email_address, $newsletter_tid, $confirm);
?>

$email_address = Subscriber's email.
$newsletter_tid = ID of newsletter
$confirm = TRUE to do email confirmation before activating subscription, FALSE if not.

 
 

Drupal is a registered trademark of Dries Buytaert.