Hi I am working on a website for a student organization of my college. In order to prevent spams, I have been looking for ways to limit account applicants only with email addresses from the college but haven't figure out how
-
Please help me with this and its very much appreciated. – user4109 Nov 20 '11 at 19:30
-
Are you using Drupal 6 or 7? – rocketeerbkw Nov 20 '11 at 22:34
-
I am using drupal 6.22 – user4109 Nov 21 '11 at 4:56
-
if Drupal 7: drupal.org/node/1405368 – chrisjlee Jan 31 '12 at 3:09
In drupal 6 you can use the built in Access Rules to limit user sign ups to certain domains. It can be found at admin/user/rules/add
This no longer exists in drupal 7 because the functionality was moved into a contrib module called User Restrictions
-
-
I'm not sure you can, your best bet would be to setup rules that would catch the majority of spammers. Have you looked into modules like Mollom as well? – digital Nov 21 '11 at 10:17
You can write a custom module that adds a validation function to the user register form, so the form does not validate if the e-mail address is not correct.
First, tell Drupal about the validation function for the user_register_form form using hook_form_FORM_ID_alter:
function mymodule_form_user_register_form_alter(&$form, &$form_state) {
$form['#validate'][] = 'mymodule_user_register_validate';
}
Next, we write the validation function. If I'm not mistaken, the email address should be available as $form_state['values']['mail']
here.
function mymodule_user_register_validate($form, &$form_state) {
$valid_email = false;
// Write your own code here to check if the email address is valid.
// If so, set $valid_email to true.
// If the email address is not valid, tell Drupal that validation failed.
if (!$valid_email) {
form_set_error('mail', t('The e-mail address %email is not valid for this site.', array('%email' => $form_state['values']['mail'])));
}
}
Please note that the code above is written with best intentions, but untested.
To build on digital's answer, I had the same issue, with the same Drupal version. I looked into the built-in Access Rules and created two rules: one that denies all email addresses fitting the mask "%" (i.e. all email addresses) and one that allows only email addresses fitting the mask "%@%.edu". Even if the rules conflict on the ".edu" addresses, it works and results in only allowing the registrations of ".edu" email addresses.
Thanks user4109 for asking that question, and thanks digital for pointing in the right and easy solution.