We've got a site where 90% of the folks registering for accounts on the site will also be registering for one or more particular events, so we'd like to add a checkbox inside the per-node signup settings for, "Add this node to the user registration form."

When a user registers, she sees the checkbox labeled with the name of the event, checks it, and once the account is created, she is signed up for it.

Any feedback or objections here :) ?

Comments

ezra-g’s picture

Status: Active » Needs review

And, here's a patch.

Notes:

- This adds a 'user_reg_form' column to the signup table
- It adds a checkbox to the per-node signup settings, which looks like this:
Only local images are allowed.
- It adds a new theme function, theme_signup_node_title() that returns a title linking to the node and also includes the date formatted according to the node's date field formatter, if it exists. This is actually something we do in uc_signup.module, so it seems like uc_signup could just rely on this theme function if it makes it into signup.module.

Here's what the fieldset and checkboxes look like on the user registration form (in a theme that is in progress ;))
Only local images are allowed.

ezra-g’s picture

StatusFileSize
new8.16 KB

Now with 100% less parse error for upgrading users.

ezra-g’s picture

StatusFileSize
new8.46 KB

And if you'll forgive the mail spam, this version of the patch adds back in a feature for which I forgot the justification before posting here, so I removed it ;).

The 'sign up for content from the user registration form' permission might seems superfluous since we already have a 'sign up for content permission' that we could just grant to anons, but it makes sense for this use case: Users who are registering are anonymous when they register, but will be signed up *as registered users* so this permission satisfies the case where you only want authenticated users signing up for events, but want to make it easier for them to sign up as they are registering.

jm.federico’s picture

Hi

did a quick check of your patch,
One question, shouldn't form alterations to user forms be made using hook_user(), when $op is "form" (for edits) or "register" (for new accounts).

Also, check at the code I have, this can be integrated with your patch. It presents admins with all open events on user registration form, so they can sign the new user when they create the account.

My sub-module is called signup_af (af for admin form).


/**
 * Implements hook_user().
 */
function signup_af_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'register':
      // Only present if is admin
      global $user;
      $admin = user_access('administer users');
      if ($admin) {
        // Present possible events on registration form
        // Get nodes that are signup enabled and that are still open
        $results = db_query('
          SELECT n.nid, n.title
          FROM {node} n
          INNER JOIN {signup} s
          ON s.nid = n.nid
          WHERE s.status = 1
          GROUP BY n.nid
        ');
        $no_results = TRUE;
        while ($row = db_fetch_array($results)) {
          $no_results = FALSE;
          $events[$row['nid']] = $row['title'];
        }
        if (!$no_results) {
          $form['signup_af'] = array(
            '#type' => 'fieldset',
            '#title' => t('Signup user to:'),
            '#tree' => TRUE,
          );
          $form['signup_af']['nodes'] = array(
            '#type' => 'checkboxes',
            '#title' => t('Available Signups'),
            '#options' => $events,
          );
        }
      }
      return $form;

    case 'insert':
      // Process only if we have results
      if ($edit['signup_af']['nodes']) {
        // Save in our own variable and set to NULL
        // api.drupal.org/api/function/hook_user/6
        $nodes = $edit['signup_af']['nodes'];
        $edit['signup_af']['nodes'] = NULL;

        foreach ($nodes as $nid) {
          // For each node, if has been checked
          if ($nid) {
            // Create signup object
            $signup = new stdClass;
            $signup->nid = $nid;
            $signup->uid = $account->uid;
            $signup->signup_time = time();
            // Save and check result
            $node = node_load($nid);
            if (signup_save_signup($signup) !== FALSE) {
              drupal_set_message(t('User signed up for !node', array('!node' => l($node->title, 'node/'. $node->nid))));
            }
            else {
              drupal_set_message(t('Error signing up for !node', array('!node' => l($node->title, 'node/'. $node->nid))), 'error');
            }
          }
        }
      }
      break;
  }
}


jenlampton’s picture

This patch only allows one user to sign up, and then complains that "anonymous" is already signed up for the event. I think you meant
$signup_form['uid'] = $account->uid;
instead of
$signup_form['uid'] = $user->uid;
on line 693.

ezra-g’s picture

Status: Needs review » Needs work

Marking as NW based on the feedback above.

ezra-g’s picture

Status: Needs work » Needs review
StatusFileSize
new10.23 KB

Here's a revised patch that implements hook_user() rather than hook_form_alter() -- Good catch, jm.federico. This also includes the fixed pointed out by jenlampton.

I didn't include the code for the proposed additional module to add the list of signups to the administrative form, but by using hook_user() case 'register' this functionality is working and assigns the signup to the newly created user.

I also made the list of nodes shown on the registration form alterable via drupal_alter(), and removed the 'sign up from the registration form' permission in favor of a setting under Signup's advanced settings, since this is arguably more of a setting than a permission, and was sufficiently confusing enough that I removed it from my initial patch and re-added it. As a setting, we can provide some descriptive text (that I've added) which explains how this feature relates to anonymous/authenticated users.

I also added the text "You will be automatically signed up once your account is created." above the list of events, to help set expectations.

Would love to get one more review before committing this :).

coltrane’s picture

+++ signup.module	29 Dec 2010 20:47:14 -0000
@@ -662,6 +710,14 @@ function signup_form_alter(&$form, &$for
+/*
+ * Implementation of hook_form_FORM_ID_alter().
+ * Make signup for events visible on the user registration form.
+ */
+function signup_form_user_register_alter(&$form, &$form_state) {
+
+}
+

Needs to be removed.

Powered by Dreditor.

ezra-g’s picture

StatusFileSize
new9.91 KB

Indeed, thanks! Here's a re-roll.

ezra-g’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Patch (to be ported)
StatusFileSize
new9.59 KB

This is committed - thanks!

I had some bad CVS metadata that denied me write access on a directory so this is unfortunately spread across two commits:
http://drupal.org/cvs?commit=473478
http://drupal.org/cvs?commit=473488

Go go Git migration!

Here it is as a single patch for porting.

dww’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev
Status: Patch (to be ported) » Needs work

Sorry I didn't look at this earlier. I have some objections. ;)

A) What happens when the signup form has custom fields? Total #fail from what I can see.

B) I don't think everyone creating a signup-enabled node should have permission to inject signup events into the site-wide user registration form.

There might be more, but that's what I noticed on a very quick skim. Drat, now I'm wishing I had made an RC7 not a 1.0 final. ;)

dww’s picture

C) I notice y'all added a drupal_alter('signup_user_reg_nids', $nids); but there's no mention of this alter hook in signup.api.php

ezra-g’s picture

Thanks for your feedback.
I'm bummed to hear that you regret the 1.0 release after all the hard work that went into that, particularly given that this was in for review ~6 months ago

Fortunately, we can still address your points in a 1.1 release.

dww’s picture

I don't really regret the 6.x-1.0 release, I was kidding. I just think it's funny that the first thing I did with signup today was create the release, *then* i actually started looking at the code as I was syncing it with HEAD. ;) I'm still big thumbs up on all the effort you spent giving this module some much needed attention!

And yes, we can fix all this in 6.x-1.1... no worries.

dww’s picture

This also introduced #1020758: Missing table prefix in query on line 643 of signup.module... ;)

Basically, the lessons for all of us should be:

- We shouldn't commit new features right before a major stable release.
- We should listen to our instincts when thinking another RC would have been a safe bet.

But yeah, none of this is a huge deal. I'm still super grateful for all the work on 6.x-1.0 release, and I'm glad it's finally out, even if it's not perfect (which it's never going to be, anyway)...

ezra-g’s picture

We should also be checking the 'signup_user_reg_form' variable before displaying any events on the user registration form.

ezra-g’s picture

> A) What happens when the signup form has custom fields? Total #fail from what I can see.

Indeed.

I think there are some features like the present one and #152659: Signup toggle link that don't really lend themselves to the signup custom fields approach and instead favor an "everyone must be a first-class user approach." I think the former is tough to accomodate in a range of use-cases and we should just document in the UI and/or README when there are features that don't work well with that approach.

My view of the signup custom fields approach (defining the fields in a theme function and serializing the values in a column in the DB) is that it's a quick way of building a super-simple site where it's not important for the data from the signup form to necessarily be re-usable in other places, and also one that is perhaps less necessary now with modules like http://drupal.org/project/signup_profile .

> B) I don't think everyone creating a signup-enabled node should have permission to inject signup events into the site-wide user registration form.

Totally agreed. Groups.drupal.org is one example of a site where that wouldn't fly.

And we still need to fix the issue in #16.

@dww - I'd love to rectify these issues, so let me know what you think, in particular of A!

ezra-g’s picture

StatusFileSize
new3.46 KB

Here's an patch that restricts users' ability to make events visible on the user registration form. Still need to address the undocumented API addition.

dww’s picture

The theme function and serialized array in the DB is a nasty hack from the 4.6.x days of signup. However, I think we have different visions about signup data...

You, COD, http://drupal.org/project/signup_profile, etc, appear to think all data belongs in the profile, and the signup is basically just a node reference field for users (to record which nodes a given user cares about). However, in my case (the reason I started using Drupal and why I maintain this blasted module) signups are per-event/per-user meta data. I'm recording stuff like what instrument people are bringing to a gig. That's not something that can be recorded once in their profile. It depends on each user and each node they're signing up for (since I might bring different instruments to different gigs depending on who else signed up, etc). Granted, the implementation for these custom fields currently sucks, and we obviously need much better plumbing for them, but I don't think we should either forget about them entirely, nor say "well, if you really want that stuff, record it in better user profiles".

I think a big part of the problem is that the default custom fields (name/phone) are *exactly* the kind of data that *should* be in your profile, not in the signup (since presumably they're not changing from event to event). But, it's impossible to have reasonable default custom fields which make general sense. Probably it'd be better to have *no* default custom fields, and just have better docs on how to use them. But, I fear if we do that, we're more likely to break the functionality since it'll be out of sight and therefore out of mind.

If I was wearing a COD hat (I won't try to turn that into a codpiece pun -- oh wait, maybe I just did), I could invent a use-case for custom signup fields. Something like if you're planning to record the session with checkboxes for audio, video, note taking, etc. Lots of people attend sessions and record them, and maybe it's nice to get a sense of who's planning to take that level of care. Okay, maybe that's a stretch, but you get the idea, right? Or even something like an "I've got a question I'd like to ask at this session" checkbox. Useful data about the fact that user X is planning to be at event Y, which isn't a property of X nor Y, but of their intersection. Make sense?

Anyway, that's a bit of a digression from this particular patch and issue, but I wanted to clarify why I still care about custom signup data that's *not* in your profile. And that is what you just asked for my input on, so there you have it. ;)

Cheers,
-Derek

ezra-g’s picture

Hey dww,

Thanks for the background info here!

Yes, there's definitely a lot of great use cases that call for per-event arbitrary fields. In my ideal world, we'd be using Webform for those fields but of course, that's a non-trivial development effort and there hasn't been a project or person with a commitment to doing that in an architecturally solid way.

Within the scope of this feature, I'm trying to get a sense of whether and how to integrate the custom fields in the user registration form.

Over at http://drupal.org/node/152659#comment-4423294, you said that

> If all you care about it a bit for if you're signed up or not (which is true for a lot of folks) a simple AJAXy toggle link is a step forward...

I was thinking that this feature is similar, in that if all you care about is if you're signed up or not, a simple *checkbox* would be a huge step forward.

Would you prefer that this get re-rolled to include the signup form serialized fields as part of the user profile form?