By ideaoforder on
Hello all,
Is there a simple/clean way of including the form for SimpleNews subscriptions on the user registration page? Though users can add that information after registering, it would be useful to allow them to elect newsletter upon registration.
I'm comfortable hacking up the code if necessary, but I've generally found there's usually an elegant way to do it instead.
Thanks
Comments
I think you can use the info
I think you can use the info on this page to display the subscription form on the registration page:
http://drupal.org/node/38630
Nope...I Tried that
Thanks...but that's the first place I looked. That's for embedding the script on a separate page. I have a client who wants this as part of the user registration--so it's something a user has to fill out, not something optional that they do later.
I guess I could make it on a separate page and force users onto that page from the registration page, but I was hoping for something a little more elegant.
Any other takers?
For what it's worth
For what it's worth...I ended up doing a redirect from the user_register function using drupal_goto and created a few new functions in the newletter module, which in turn bring the user to a welcom page. So the registration becomes a two step process.
If anyone would like the gory details, I'd be happy to supply them.
Rock.
Help!
Is there any non-coding way of doing this?
Yours, a very non-techy Drupal user
Mike
Not that I know of
Hey Mike,
That's what I was hoping for too, but never came up with anything. I'd be more than happy to send you my hacked versions of user.module and simplenews.module. You should be able to just paste them into the "modules" directory over the old modules and go from there...actually, you also have to make a static page or two--I can give you the names and the code that should get pasted.
Though it sounds a little sloppy, the execution is pretty elegant. The org I did it for was perfectly happy.
Cheers,
Mark
Yeah, I'd love that if you could send them to me!
Thanks!
Mike
mbites.com
May I have a copy of these
May I have a copy of these as well?
thanks,
Maria
Here it is for 4.7
The following code goes into simplenews_user(). The "register" case is new, and the "insert" case replaces the existing one.
There is provision for a default newsletter. To use this feature set a value named "simplenews_default_subscription" into the variables table, or run the following code:
...where 123 is the tid (refer to sn_snid_tid db table) of the newsletter you wish to set as default.
Cheers.
Little confused on this.
Little confused on this. Where about does this actually go and what do i replace ?
--
http://www.porttalbotchat.co.uk
-------------------------------------------------
Our mission is to discuss issues and topics of residents of Port Talbot. We provide info on events, issues, concerns and discussions of our local area.
It goes in
It goes in simplenews.module, in the function simplenews_user (~line 410). The cases belong in the switch ($op) conditional. Currently there is no case for "register" so just paste it in, but the case for "insert" provided in the code above replaces the existing case.
Oh heck here is the entire function...
Slight tweak?
When I use the patch, above, I get the Simplenews subscription form all right at registration time, but an extraneous line of text is added just below the title of the box and just before the list of newsletter checkboxes. That text is, in fact, one of the newsletter's names, in bold, with a colon at the end of it. I'd add a screenshot, but I don't appear to have privs. Any idea why this is? And/or a fix?
Also... how would one enhance this newsletter form in order to display the newsletters' description fields below each name? Simplenews offers a description field in addition to the name, but doesn't appear to render this description text anywhere. I'd REALLY like to be able to show description text for my newsletters.
Am yet another non-PHP weenie that would really benefit from others' assistance(!) Thanks.
Remove title and add description
You'll need to replace the "register" and "insert" cases in the simplenews_user function (line 410).
Works great
Implemented the above and it works as advertised. Thanks, chris_five.
New wrinkle
Not sure if this is related to the code above, but I just installed the LoginToboggan module, and am now getting duplicate subscribers in simplenews.
Previously, simplenews did a good job of checking email addresses at registration time to ensure duplicates weren't made in its subscription database. If an email address of an unregistered user had previously been imported, and then that user with that email address subsequently registered themselves an account in Drupal, only a single email address would still exist in the subscription database -- the username shown in the subscriber list would previously have been "unregistered user", but would become the actual username upon registration.
Now that logintoboggan is installed, I'm getting a separate subscription created for EVERY newsletter the user subscribes to. So if they subscribe to two newsletters at registration time, I actually end up with THREE entries in the simplenews subscribers database: a separate entry for each newsletter requested, plus the original unregistered user previously imported. To badly paraphrase Highlander, "there should be only one!" :)
Help!
Having the same problem here
...except that I'm not getting an error. Likely just some bad checking.
I'm looking into it.
New wrinkle part II
So, in my efforts to get simplenews working, I've temporarily disabled LoginToboggan.
And lo and behold, simplenews subscriptions now work properly.
But ... I also now get an error reported after clicking the register button if the registrant's email already exists in the simplenews database because it had previously been imported.
Duplicate entry '35-27' for key 1 query: INSERT INTO sn_snid_tid (snid, tid)
VALUES (35, 27) in
/home/content/c/t/c/ctchronicle/html/includes/database.mysql.inc on line
120.
Ran across a thread (here http://drupal.org/node/65665) on Drupal.org that
suggests I should delete the sn_snid_tid table and recreate snid and tid as
auto-incrementing. Advisable?
Let me repeat that things DO indeed now technically work as they should. It's just the reporting of this error that's unfortunate.
FYI, in trying to get to the bottom of this I've recently exchanged email with Dries Knapen, the developer of simplenews, and he believes my issues may be related to the "case insert" code in chris_five's patch, which he believes is wrong for several unspecified reasons.
The problem with case "insert"
...is that it does not use the "simplenews_process_subscription" function to insert. Using it fixes the duplicate entry into the "sn_subscriptions" table, but inserts a tid of "0" in table "sn_snid_tid" no matter how many newsletters are checked. I should be able to figure it out soon.
BTW, I do NOT recommend auto-incrementing snid and tid in the "sn_snid_tid" table. That would make absolutely no sense.
Too bad the developer didn't suggest a solution.
Had to change simplenews_process_subscription
... b/c it checks for $user->uid instead of $uid. It looks as if "we" have found a solution ;-)
2 functions enclosed:
Works Great
I did exactly what you said. Works flawlessly. It might do with the newsletter description, but it's not really important. Might think of a fix for it.
Thank you chris_five for your help :)
http://www.2knowmyself.com - The Ultimate Source for Self-Understanding and Personal Development.
Glad to hear...
...that we're on the right track. I'll stay watching this thread eagerly for a suggested fix.
Works great
Thanks for this. I was able to test your work only tonight.
The patch above fixed my bugs (hooray!), but unfortunately also TOOK AWAY the feature you'd incorporated earlier that showed the newsletter descriptions under the newsletter names at registration time. As patched now, only the newsletter names show beside the checkboxes.
Possible to resurrect the newsletter descriptions?
Thanks a million. This works great now.
Also ... phantom newsletter name back again
In addition to my comment above, as previously reported October 3rd, above, an extraneous line of text is being added just below the title of the box and just before the list of newsletter checkboxes. That text is, in fact, one of the newsletter's names, in bold, with a colon at the end of it. Am anxious to get rid of it, in addition to getting the descriptions of the newsletters back.
Fixed
In function simplenews_user, replace the "register" case with the one below:
Thanks for testing!
Looks good, but generates errors
So, your change above takes care of the optics (the registration form now LOOKs great) but after registering a new user, has created a bunch of errors as follows:
After registration of a new account, but before clicking on the confirmation link (I'm using LoginToboggan), trying one of the pages of my site where access is restricted to registered users gives the appropriate access denied message, but ALSO generates the following user warning:
user warning: Unknown column 'users.uid' in 'field list' query: SELECT node.nid, users.uid AS users_uid, node.title AS node_title FROM node node ORDER BY created DESC LIMIT 0, 1 in /home/.justy/gtink/insidegreentech.com/includes/database.mysql.inc on line 121.
Then, after the email registration link is clicked, the user is sent to the home page as he should be, but the following two errors are reported, not just in watchdog but to the user as well:
user warning: Unknown column 'users.uid' in 'field list' query: SELECT node.nid, users.uid AS users_uid, node.title AS node_title FROM node node ORDER BY created DESC LIMIT 0, 1 in /home/.justy/gtink/insidegreentech.com/includes/database.mysql.inc on line 121.
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN ('content_weekly_quote')) ORDER BY created DESC LIMIT 0, 1' at line 1 query: SELECT node.nid, node.title AS node_title, node_data_field_newsmaker_name.field_newsmaker_name_value AS node_data_field_newsmaker_name_field_newsmaker_name_value FROM node node LEFT JOIN node_content_weekly_quote node_data_field_newsmaker_name ON node.vid = node_data_field_newsmaker_name.vid WHERE (.type IN ('content_weekly_quote')) ORDER BY created DESC LIMIT 0, 1 in /home/.justy/gtink/insidegreentech.com/includes/database.mysql.inc on line 121.
Clicking on other pages of my site, in particular node lists, results in:
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= term_node. WHERE (.status = '1') AND ((term_node.tid = '6'))' at line 1 query: SELECT count(node.nid) FROM node node LEFT JOIN term_node term_node ON . = term_node. WHERE (.status = '1') AND ((term_node.tid = '6')) in /home/.justy/gtink/insidegreentech.com/includes/database.mysql.inc on line 121.
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= term_node. WHERE (.status = '1') AND ((term_node.tid = '6')) ORDER BY sticky ' at line 1 query: SELECT node.nid FROM node node LEFT JOIN term_node term_node ON . = term_node. WHERE (.status = '1') AND ((term_node.tid = '6')) ORDER BY sticky DESC, created DESC LIMIT 0, 10 in /home/.justy/gtink/insidegreentech.com/includes/database.mysql.inc on line 121.
user warning: Unknown column 'users.uid' in 'field list' query: SELECT node.nid, users.uid AS users_uid, node.title AS node_title FROM node node ORDER BY created DESC LIMIT 0, 1 in /home/.justy/gtink/insidegreentech.com/includes/database.mysql.inc on line 121.
I'm not getting these errors on another server that has your code on it, with LoginToboggan, but DOESN'T have this latest patch above applied.
Unfortunately, the server that's generating the errors is my production one - I installed your patch on the wrong server. Rolling back before today's patch has not fixed the issue. I'd appreciate your guidance in helping restore the integrity of my production site's user db. Thx.
I cannot reproduce
I'm also using logintoboggan (v1.7.2.43), but I have not set up a Non-authenticated role.
Looking at your SQL, it looks as though something is generating wonky queries. For example, the following is clearly missing a reference to the "users" table, but I have no idea where this is being generated.
My patch no longer includes any SQL, but only uses built-in simplenews functions to do all the processing.
If you are on Dreamhost, you can roll back your DB. Otherwise, you might have to go into the DB itself and surgically remove the offending records. Have you have a look at the term_node, node, and user tables?
I am using the patch without any errors. It may have to do with other modules you're using.
Lemme know how it goes.
Database restored
I've restored my db and after hammering with new user accounts am having a hard time reproducing the problem, myself. Will post more if/when it returns. Thanks.
Great to hear that it's
Great to hear that it's working for you. It'd be nice to know how it's doing with anyone else who is using this patch.
white page after submission
It works fine for me.... just a little fix is needed... I get a blank page after the submission of registration form. The user gets registered anyway, but I would really love to fix this annoying thing. Any suggestion?
I haven't run into this
I haven't run into this problem, but I can't recall whether it's been tested without the logintoboggan module installed.
Can you tell me what version of Drupal and simplenews you're using? I'll have a look when I get some time.
Sorry, I'm lost...
Sorry, I'm trying to understand the posts above, but I'm a bit lost.
What I'm trying to achieve: Every user that signs up is automatically subscribed to a certain newsletter.
How can I do this? It's ok if I just hard-code it into the module. Don't know that much about Drupal dev, so could anyone help?
Cheers,
Kai
Webdesign Melbourne Australia
www.brizk.com
You have to modify your
You have to modify your simplenews.module file, in the sections outlined above.
To automatically subscribe all new users to a newsletter, you have to first create the newsletter. Then you have to run the code provided in http://drupal.org/node/41745#comment-156216 ONCE, where "123" is the term id of the newsletter that you want new users to be automatically subscribed to. Alternatively, you can use a tool like PHPMyAdmin to insert it into the "variables" database table.
You can find out the id of newsletters by looking at the database table "sn_snid_tid".
Auto-subscribe via hidden text field
I was actually after a technique that automatically subscribes all new users to the default newsletter - so they DON'T get to see this checkbox but are automatically added to the subscriber list (via a hidden text field)
Does anyone know how to change the code above to use a hidden text field to add the email address to the list?
They can unsubscribe anytime in their user menu.
Kai
Webdesign Melbourne Australia - www.brizk.com
Work Travel Australien - www.ausmag.de
Thats more what im after too
Thats more what im after too to be honest. Any help appreciated.
--
http://www.porttalbotchat.co.uk
-------------------------------------------------
Our mission is to discuss issues and topics of residents of Port Talbot. We provide info on events, issues, concerns and discussions of our local area.
change to hidden form fields
You should be able to change the form to accommodate $form['simplenews']['newsletters'] '#type' => 'hidden'.
Forms API here: http://api.drupal.org/api/4.7/file/developer/topics/forms_api.html
Lemme know how it goes.
Chris
thanks! could anyone try it
thanks!
could anyone try it and post the final code here, so that we all know how to do it? I'm currently not at home and can't implement it.
help is much appreciated! :-)
cheers,
kai
----
Webdesign Melbourne Australia - www.brizk.com
Work Travel Australien - www.ausmag.de
easier method to subscribe
easier method to subscribe everyone to a newsletter is to use the simplenews_role.module that allows to auto subscribe all users from a certian role to a newsletter. So all autheticated users can be subscribed automatically and unsubscribe if they want from their account.
The fix for the first issue (presenting the newsletter checkbox at subscription) seems good I'll try to try it soon.
simplenews_role.module
Where can I download it?
Go to this
Go to this page:
http://drupal.org/node/49980
At the time of posting, the module is submitted at update #25 and a patch to apply to the module is at #37. Phew! Took some searching!
Update for 5.x?
It'd be nice to do this in 5.x as well.
Also interested in 5.x
I would also like to have this feature for Drupal 5.x. Thanks in advance.
It's now included
The feature to subscribe at user registration has made it into simplenews. You find it in both 5.x-1.x-dev development release and HEAD.
-- Sutha
-- Erik
After being missing in action
After being missing in action, this feature has reappeared at http://drupal.org/node/178485. This will hopefully be the official and supported way to enable subscription at registration time and I encourage everyone to test the patch (and please provide feedback).
use simplenews_register module
http://drupal.org/project/simplenews_register
1 year later but thanks
I was developing a module like this and I've found the module you commented. Thanks bud!