We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19889
    • 616 Posts
    While I’m having problems to get the websignup snippet to work I was wondering whether there is a websignup based on eform.

    thank you for your input.

    by the way, the problem I’m experiencing is that I’m always told that there is the username missing although it’s not.
      • 24719
      • 194 Posts
      are you using captcha codes? i’ve had problems with that before, so i’ve had to turn them off.
        • 24719
        • 194 Posts
        hi,

        here’s something to get you started. it’s quck and dirty to fulfill my needs. it won’t work with the standard web sign up form either since i’ve renamed some fields (like password1 and password2, and i’ve split a user’s name up into title, first name and last name). anyway, here’s the code for a snippet called eForm_userSignUp:

        <?php
        /* Note: The group that the user is inserted into is hard-coded. sloppy, but well... */
        if (!function_exists(eForm_userSignUp))
        {
            function eForm_userSignUp(&$fields, &$vMsg, &$rMsg)
            {
                global $modx;
                
                $username = $modx->db->escape($modx->stripTags($fields['username']));
                $email = $modx->db->escape($modx->stripTags($_POST['email']));
                $first_name = $modx->db->escape($modx->stripTags($_POST['first_name']));
                $last_name = $modx->db->escape($modx->stripTags($_POST['last_name']));
                $sql = "SELECT id FROM ".$modx->getFullTableName("web_users")." WHERE username='$username'";
                    
                if(!$rs = $modx->db->query($sql))
                {
                    //$output = webLoginAlert("An error occured while attempting to retreive all users with username $username.").$tpl;
                    return;
                } 
                $limit = $modx->db->getRecordCount($rs);
                if($limit>0) 
                {
                    $vMsg[] = "The user name you have chosen is already in use. Please choose another one.";
                }        
                
                if ($fields['password1'] != $fields['password2'])
                {
                    $vMsg[] = "Your passwords don't match. Please re-type them.";
                    $fields['password1'] = '';
                    $fields['password2'] = '';
                }
        
        		// check for duplicate email address
        		$sql = "SELECT internalKey FROM ".$modx->getFullTableName("web_user_attributes")." WHERE email='$email'";
        	    if(!$rs = $modx->db->query($sql)){
           	     //$output = webLoginAlert("An error occured while attempting to retreive all users with email $email.").$tpl;
                	return;
            	} 
            	$limit = $modx->db->getRecordCount($rs);
            	if($limit>0) 
            	{
              	  $row=$modx->db->getRow($rs);
                	if($row['internalKey']!=$id) 
                	{
                    $vMsg[] = "The email address you have entered is already registered at this site. Please use a different one.";
                	}
            	}
            	// if there have been any errors, return the form to the user.
              if (count($vMsg) > 0 || count($rMsg) > 0) return;
              
              // create the user account
            	$sql = "INSERT INTO ".$modx->getFullTableName("web_users")." (username, password) 
                    VALUES('".$username."', md5('".$password1."'));";
            	$rs = $modx->db->query($sql);
            	if(!$rs)
            	{
                //$output = webLoginAlert("An error occured while attempting to save the user.").$tpl;
                return;
            	}
            	
            	    // now get the id
        		$key=$modx->db->getInsertId();
        	
        		// save user attributes
        		$sql = "INSERT INTO ".$modx->getFullTableName("web_user_attributes")." (internalKey, fullname, email) 
        					VALUES($key, '$first_name $last_name', '$email');";
        		$rs = $modx->db->query($sql);
        		if(!$rs){
        			//$output = webLoginAlert("An error occured while attempting to save the user's attributes.").$tpl;
        			return;
        		}
        
        		// add user to web groups
        		$ds = $modx->dbQuery("SELECT id FROM ".$modx->getFullTableName("webgroup_names")." WHERE name='web_users'");
        		if(!$ds) return;// $modx->webAlert('An error occured while attempting to update user\'s web groups');
        		else {
        			while ($row = $modx->fetchRow($ds)) {
        				$wg = $row["id"];
        				$modx->dbQuery("REPLACE INTO ".$modx->getFullTableName("web_groups")." (webgroup,webuser) VALUES('$wg','$key')");
        				}
        		}
        
            // invoke OnWebSaveUser event
            $modx->invokeEvent("OnWebSaveUser",
                                array(
                                    "mode"         => "new",
                                    "userid"       => $key,
                                    "username"     => $username,
                                    "userpassword" => $password1,
                                    "useremail"    => $email,
                                    "userfullname" => $first_name. ' ' . $last_name
                                ));
             
             // send sign-up email
             $snipPath = $modx->config['base_path'] . "assets/snippets/";
                include_once $snipPath."weblogin/weblogin.common.inc.php";
                
            $rt = webLoginSendNewPassword($email,$username,$password1,$first_name. ' ' . $last_name);
            if ($rt!==true) { // an error occured
                //$output = $rt.$tpl;
                return;
            }
        
            }
        }
        ?>
        


        here’s the call on the page you want to use it on:

        [[eForm_userSignUp]]
        [[eForm? &tpl=`UserSignUpFrm` &formid=`UserSignUpFrm` &noemail=`1`  &requiredClass=`required` &vericode=`1` &eFormOnValidate=`eForm_userSignUp`]]
        


        this was all copied from the websignup code, so thanks Raymond Irving.
        hope this helps...

        ps - there may be some issues with sending an email to confirm the sign up, but i’m not sure
          • 19889
          • 616 Posts
          I’ll give it a go - thank you - really appreciate your input