if (!in_array(trim($edit['regcode_code']), $regcodes)) {
            form_set_error('regcode_code', t('Invalid registration code'));
            watchdog('regcode', t('User entered invalid registration code: ') .
            $edit['regcode_code'], WATCHDOG_WARNING);
          }else{
//reg code successful now remove it or mark it as being used, so it cant be used more than once.
//code required
}

Comments

d------’s picture

case 'validate':
        if (($category == 'account') && (!$account->uid)) { 
          // Make sure that the entered code is in the list.
          $regcodes = explode("\n", $regcodes);
          array_walk($regcodes, create_function('&$a', '$a = trim($a);'));
          if (!in_array(trim($edit['regcode_code']), $regcodes)) {
            form_set_error('regcode_code', t('Invalid registration code'));
            watchdog('regcode', t('User entered invalid registration code: ') .
            $edit['regcode_code'], WATCHDOG_WARNING);
          }else{
          /*
          reg code exists, delete it so it cant be used again.
          Best way may be to remove from the array... 
          any ideas how to remove the reg code from the array and save it at this point?
          */
          }
        }
        break;
jvermillion’s picture

regcode is more like a password for signing up for the site. Everyone who is invited to the site is given the same registration code. This "fix" would only be useful if the regcodes were individually generated.

bakwas_internet’s picture

if (!in_array(trim($edit['regcode_code']), $regcodes)) {
            form_set_error('regcode_code', t('Invalid registration code'));
            watchdog('regcode', t('User entered invalid registration code: ') .
            $edit['regcode_code'], WATCHDOG_WARNING);
          }
          // code to remove the reg code which has been used once
          else
          {
          	$removekey= array_search(trim($edit['regcode_code']), $regcodes);
          	unset ($regcodes[$removekey]);
          }

I have written this code for removing the used regcode , but I have no idea how to save the new array at this point. Can someone please point me to related api or functions.

bakwas_internet’s picture

Did some more hacking and finally came up with following code. This is working fine on my system. Can other people test it and give me their feedback.


     if (!in_array(trim($edit['regcode_code']), $regcodes)) {
            form_set_error('regcode_code', t('Invalid registration code'));
            watchdog('regcode', t('User entered invalid registration code: ') .
            $edit['regcode_code'], WATCHDOG_WARNING);
          }
          // code to remove the reg code which has been used once
          else
          {
          	$removekey= array_search(trim($edit['regcode_code']), $regcodes);
          	unset ($regcodes[$removekey]);
          	$regcodestring= join("\n",$regcodes);
          	variable_set('regcode_codes',$regcodestring);
          }
        }
        break;
bakwas_internet’s picture

Status: Needs work » Needs review
colan’s picture

Status: Needs review » Closed (duplicate)

This is a duplicate of http://drupal.org/node/154355.