views:

22

answers:

1

I'm using expressionengine as a CMS but want to override the core validation for new users. When someone registers as a new user, the system checks to see if the screen_name is already taken. If it is, then it throws an error flag.

I've found the section of code that's doing the validation but I'd like to change it so that instead of throwing and error the screen_name is appended with a space and number (one above the count value.

So "John Smith" gets changed to "John Smith 3" (assuming there are two other "John Smith" screen_names in the db).

How can I modify this code to acheive this?

        /** -------------------------------------
        /**  Is screen name taken?
        /** -------------------------------------*/

        if (strtolower($this->cur_screen_name) != strtolower($this->screen_name))
        {
            $query = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE screen_name = '".$DB->escape_str($this->screen_name)."'");

            if ($query->row['count'] > 0)
            {                            
                $this->errors[] = $LANG->line('screen_name_taken');
            }
        }
+1  A: 
if (strtolower($this->cur_screen_name) != strtolower($this->screen_name))
{
    $query = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE screen_name = '".$DB->escape_str($this->screen_name)."'");

    if ($query->row['count'] > 0)
    {   
        $query2 = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE screen_name LIKE '".$DB->escape_str($this->screen_name)."'");
        $name = $DB->escape_str($this->screen_name).$query2->row['count']; 
        $this->errors[] = 'The screen name you choose is taken please use '.$name.' for your new  screen_name);
    }
}

Have fun!

DCC
I'd like to do this automatically - without showing the error message. I'd like to update the value of screen_name without an error message. How do I append just $name back into $this->screen_name ?
proee
That's something you should work on in the GUI part maybe using jquery/prototype/dojo.You could modify the $this->errors[] = $name; and in the javascript part this will update the field 'screen_name' in the form.
DCC
Can I just replace your last error line with:$this->screen_name=$name
proee
Sure but I have no idea if this will work properly it all depends on the code logic behind it.Give it a try :)
DCC
Thanks... How do I append a space between the screen_name and the count value on this line?$name = $DB->escape_str($this->screen_name).$query2->row['count'];
proee
$DB->escape_str($this->screen_name).' '.$query2->row['count'];Enjoy!
DCC