-
☆ A M B ☆
- 24,524 Posts
Here’s a little snippet to take care of the first part of newsletter handling. It generates a single text-input form to take the user’s email, and processes it.
First it checks to see if the email is already in use. If not, it creates a new user using the email as the username and email, and sets an md5 has of a timestamp as a temporary password. Either an admin can edit the user to change the password or the user can request a new password as usual to get a valid login. The new user is added to the specified group.
If the email is in use, it checks to see if that user is already a member of the newsletter group. If not, it adds the user to the group.
Apprpriate messages, error and success, are returned at every step. It will even remove the new user from the web_users table if the email insertion into the web_user_attributes table fails; if there is no email in the web_user_attributes table the user won’t show in the MODx user manager, leaving a nasty orphaned user in the web_users table.
Modified: April 30
Version 1
Adds automatic removal of user from web user group
Code cleanup and more validations
-
☆ A M B ☆
- 24,524 Posts
Final Version 1. File available from first post in topic.
Creates a new user if necessary using the email as a username and generating a random password.
Adds user to the given web user group.
Removes user from the given web user group if button is checked. Does not remove user from web users.
Will silently return if no valid web user group is supplied in the snippet call options; the form will not be displayed.
The form and all output text is configurable at the beginning of the snippet code.
Sorry Susan for not replying earlier about this new snippet, which is a(nother) great addition

I didn’t even make it to test this yet that there is a new version ! This is one of those essential snippets that MODx needs to build webzines or communities
I’ll make sure to test this sometime this week...
.: COO - Commerce Guys - Community Driven Innovation :.
MODx est l'outil id
Agree with DavidM. Awesome. Me wants the next step ... me is always hungry for more.
Ok, tried this snippet and only got it partly working.
First I made a new group ’newsletter’ in Users > Web permissions > Web User groups.
Then I call the snippet with [[NewsletterRegistration? &usergroup=`newsletter`]].
Ok, I get the form, all seems well.
I add an email address, submit and it reports succes. Indeed, a user with that email has been added to etomite_web_users sql table.
Now, when I do the same thing again, so same email and submit, I get this error:
« Execution of a query to the database failed - 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 ’)’ at line 1 »
SQL: INSERT INTO `mydbname`.etomite_web_groups (webgroup, webuser) VALUES (1,)
Trying to remove the email, same error. I do see the users don’t get assigned to the group..
Anyone has an idea?
Thanks.
Btw: just upgraded from etomite and what a relieve wished I knew about MODx a long time ago!
-
☆ A M B ☆
- 24,524 Posts
Hm. Looks like it’s not picking up on the web user’s ID. I’ll look into it. May be a typo in the file; anybody else run into this?
Indeed a typo, check line 87:
// add the user to the group
$sql = "INSERT INTO ".$modx->getFullTableName(’web_groups’)." (webgroup, webuser) VALUES (".$gid.",".$uid.")";
$uid should be $id
Thanks.
Found a bug, when you remove an address twice, it actually registers the email address..
If you then normally subscribe the address, it leaves a blank response.
Thanks again.