CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • HOWTO: Add a checked checkbox to user registration for list subscriptions
Pages: [1]

Author Topic: HOWTO: Add a checked checkbox to user registration for list subscriptions  (Read 1017 times)

EvanDonovan

  • Guest
HOWTO: Add a checked checkbox to user registration for list subscriptions
March 18, 2010, 04:04:20 pm
Earlier today, I worked for a few hours, with dgg and dlobo's help on IRC, to add a checked checkbox for a particular group to my user registration form, so that people would be automatically subscribed to a mailing list, but could opt out if they wished.

Here's how I did it:

1) Make sure that only the groups you want to show in the register form are set to Public visibility. You can still subscribe people to other groups via the API (such as via the CiviSubscribe module).
2) Create a new Custom Profile and set to be used in User Registration.
3) Add the Group(s) field (which is under Contacts, I believe) to the form. You can give it a different label.
4) Add a hook_form_alter in a custom module to make the checkbox checked. With some help from DamZ in #drupal & cohitre on #jquery, I came up with the following code. It worked for me, at least. Note that $scripts must be in the <head> of your theme, to avoid getting the dreaded "$ is undefined" JS error.

Code: [Select]
function HOOK_form_alter(&$form, $form_state, $form_id) {
  if($form_id == 'user_register') {
      $form['#prefix'] =
'<script type="text/javascript">
  $(document).ready(function() {
            $("#editrow-group :checkbox").attr("checked", "checked")
          });
</script>';
}
}

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • HOWTO: Add a checked checkbox to user registration for list subscriptions

This forum was archived on 2017-11-26.