Support Forums

Using an extra field to set user group

This is a discussion on Using an extra field to set user group within the Technical Support forums, part of the Technical Support Forums category; What version of 68 Classifieds are you running? V 4.2.1 What template are you using? default Please describe in detail ...


Go Back   68 Classifieds Forums > Technical Support Forums > Technical Support

Reply
 
Thread Tools Display Modes
Old 03-05-2011, 10:49 PM   #1
Customer
 
Join Date: Mar 2011
Posts: 5
Rep Power: 0
misterp is on a distinguished road
Default Using an extra field to set user group

What version of 68 Classifieds are you running?
V 4.2.1

What template are you using?
default

Please describe in detail the issue you are having:

Hi All
I've created a user group called Traders (id=6) and have set my extra2 field to a radio button that allows you to select your user type as 'Private Seller' or 'Trader' and I want this field to be used to set the user group as you confirm a user account.
I've had a good look through the forum but I'm a php beginner so can anyone tell me what im doing wrong?
I dont know if where I've got if ($extra2=="2") in register.php is the right way to read a variable from another page because everytime I add a user it always sets them to registered user (id=2).

Ok so in userjion.tpl i've got the following to create a radio button for extra2:

{if $dis_extra2=="Y"}
<p class="{cycle values="row1,row2" advance=true}">
<label for="extra">
{if $req_extra2=="Y"}<span class='required'>{$smarty.const.LANG_STAR}</span>{/if}{$extra2_text} {$smarty.const.LANG_COLON}</label>
<input {if $req_extra2=="Y"}class="required"{/if} name="extra2" type="radio" id="extra2" value="1" size="{$smarty.const.FIELD_SIZE}" /> Private Seller
<input {if $req_extra2=="Y"}class="required"{/if} name="extra2" type="radio" id="extra2" value="2" size="{$smarty.const.FIELD_SIZE}" /> Trader
</p>
{/if}

And in register.php I've got the following:

function confirm ($confirmCode)
{
$sql = 'SELECT uVerify FROM ' . PREFIX . 'users WHERE uVerify=' . $this->_db->quoteInto ($confirmCode) . ' AND level<>"4"';
$result = $this->_db->query($sql);
if ($result->size() != 1 || $this->_db->isError()) {
return false;
}
if ($extra2=="2")
{
$result->freeResult();
$sql = 'UPDATE ' . PREFIX . 'users SET level=6 WHERE uVerify=' . $this->_db->quoteInto ($confirmCode);
$result = $this->_db->query($sql);
if ($result->affectedRows() != 1 || $this->_db->isError()) {
$result->freeResult();
return false;
}
}
else
{
$result->freeResult();
$sql = 'UPDATE ' . PREFIX . 'users SET level=2 WHERE uVerify=' . $this->_db->quoteInto($confirmCode);
$result = $this->_db->query($sql);
if ($result->affectedRows() != 1 || $this->_db->isError()) {
$result->freeResult();
return false;
}
}
$modules = Library::loadLibrary('Modules');
$modules->call_hook('user_confirm', $userDetails); // Call any module functions
$result->freeResult();
return true;
}

Many thanks in advance for any help

UPDATE: forgot to say I have tried changing extra 2 to a text field and changin the if statement to if ($extra2=="Trader") but it didnt work which makes me pretty sure im not passing reading this variable properly (PHP noob)

Last edited by misterp; 03-05-2011 at 10:58 PM. Reason: erm more info?
misterp is offline   Reply With Quote
Old 03-05-2011, 11:24 PM   #2
Developer & Moderator
 
 
Join Date: Jan 2007
Location: Pennsylvania, USA
Posts: 2,147
Rep Power: 63
Mike-N-Tosh is just really nice Mike-N-Tosh is just really nice
Default

First thing I will say is that I would recommend that you do not modify the core file as you are. This will make upgrading to a newer version much more difficult (especially as I don't see any documentation within your code for the modifications). I would also recommend making your own custom template from a copy of the default template if you are going to modify it as well.

You will notice that further down in the code (register.php) there is this little handy bit:
PHP Code:
$modules->call_hook('user_confirm'$userDetails); 
That is so that you can create a completely separate Module to handle your own code so that you don't modify core files. I would highly recommend that you revert the core file back to it's original state and handle this in your own custom module. (Developers documentation - modules)

Regarding the code that you posted (No, I didn't actually open the original file, just looking at your code), I don't actually see you getting the value of the posted variable $extra2 (e.g. $extra2 = $_POST['extra2']), therefore the variable would be set to NULL regardless if the user input a value.
__________________
Mike-N-Tosh
IndianaPC.org - A community website (v3.1.10 Developer - heavily modified & used as the CMS)
Sandbox [localhost(v3.1.10, v4.0.9, 4.1.10,4.2,5.0)] for development and customization
Visit My blog: reviews, tips, tricks, tutorials and my store with Templates, Mods & Docs
Web Hosting | Web Design & Development | 68 Classifieds Customizations
I am not a 68C employee, just a user and try to help out
Mike-N-Tosh is offline   Reply With Quote
Old 03-06-2011, 07:32 AM   #3
Customer
 
Join Date: Mar 2011
Posts: 5
Rep Power: 0
misterp is on a distinguished road
Default

Hi
Thanks for the advice Im going to look into transfering this functionality into a module asap and will create a new template that I can modify (I'm going to swallow a couple of php book in work this week)

where would I put this line of code to see this working today
$extra2 = $_POST['extra2']

I've tried putting it in register.php within the confirm function, just above if ($extra2=="2") as:
$extra2 = $_POST['extra2']);

obviously it will have to be moved when the module is set up but I just want to know why its not picking up that someone has selected that they are a trader. I'm almsot positive this code should read the variable properly

iheartwheels.com if you wanted to see the register page.
Many thanks
Sam

I've just tried
$extra2 = ($this->_userData['extra2']);
if ($extra2 == "Trader")

no luck...

I've checked te data base and the Extra2 field is definatley populated with 'Trader' so surely
$extra2 = $_POST['extra2'];
if ($extra == "Trader")
should definaltey work?

Last edited by misterp; 03-06-2011 at 10:33 AM.
misterp is offline   Reply With Quote
Old 03-06-2011, 11:33 AM   #4
Developer & Moderator
 
 
Join Date: Jan 2007
Location: Pennsylvania, USA
Posts: 2,147
Rep Power: 63
Mike-N-Tosh is just really nice Mike-N-Tosh is just really nice
Default

I actually took a look at the Register.php class file and now see exactly why your code doesn't work, or the code I suggested doesn't work.

You are doing this in the email confirmation. The database query is only getting one piece of information:
PHP Code:
$sql 'SELECT uVerify FROM ' PREFIX 'users WHERE uVerify=' $this->_db->quoteInto ($confirmCode) . ' AND level<>"4"'
Which is the uVerify field (e.g. the confirmCode)

As this function is being run from a link in the email there is NO $_POST data, because they didn't fill in a form. The only information available is the uVerify field.

So you need to run a query in the database table to get the $extra2 value. something like this:
PHP Code:
$extraSQL 'SELECT extra2 FROM' .PREFIX.'users WHERE uVerify = ' $this->_db->quoteInto($confirmCode);
$exresult =  $this->db->query($extraSQL);
// run my logic 
if ( $exresult->size()==)
{
   
$exrs $exresult->fetch();
   
$extra2 $exresult['extra2'];
   if ( 
$extra2 == "2" )
   {
        ..... 
__________________
Mike-N-Tosh
IndianaPC.org - A community website (v3.1.10 Developer - heavily modified & used as the CMS)
Sandbox [localhost(v3.1.10, v4.0.9, 4.1.10,4.2,5.0)] for development and customization
Visit My blog: reviews, tips, tricks, tutorials and my store with Templates, Mods & Docs
Web Hosting | Web Design & Development | 68 Classifieds Customizations
I am not a 68C employee, just a user and try to help out
Mike-N-Tosh is offline   Reply With Quote
Old 03-06-2011, 04:18 PM   #5
Customer
 
Join Date: Mar 2011
Posts: 5
Rep Power: 0
misterp is on a distinguished road
Default

So if I combine what you've given me with the code i've got for setting the user name it looks like this, however it gets as far as sending the confirmation email out, you can click on the link it brings uo the login box successfully but when you try and lig in it says you havent registered and do you want to re-send the confirmation e-mail.
Is it the fact that theres two SQL queries in this one function that messes it up. I tried to combine it into one sql query (i.e select uVerify AND extra2) but didnt get very far with it.
Although since two variables are used fir the sql statements $sql and $extrasql i dont see why this is failing?
Any more advice appreciated.

PHP Code:
function confirm ($confirmCode)
    {
        
$sql 'SELECT uVerify FROM ' PREFIX 'users WHERE uVerify=' $this->_db->quoteInto($confirmCode) . ' AND level<>"4"';  
        
$result $this->_db->query($sql);
        if (
$result->size() != || $this->_db->isError()) {
            return 
false;
        }
        
        
$extraSQL 'SELECT extra2 FROM' .PREFIX.'users WHERE uVerify = ' $this->_db->quoteInto($confirmCode); 
        
$exresult =  $this->db->query($extraSQL); 
        
// run my logic  
        
if ( $exresult->size()==
        { 
            
$exrs $exresult->fetch(); 
            
$extra2 $exresult['extra2'];
            if (
$extra2=="Traders")
            {
                
$result->freeResult();
                
$sql 'UPDATE ' PREFIX 'users SET level=6 WHERE uVerify=' $this->_db->quoteInto($confirmCode);
                
$result $this->_db->query($sql);
                if (
$result->affectedRows() != || $this->_db->isError()) {
                
$result->freeResult();
                return 
false;
                }
            }
            else
            {
                
$result->freeResult();
                
$sql 'UPDATE ' PREFIX 'users SET level=2 WHERE uVerify=' $this->_db->quoteInto($confirmCode);
                
$result $this->_db->query($sql);
                if (
$result->affectedRows() != || $this->_db->isError()) {
                
$result->freeResult();
                return 
false;
                }
                                                                          
            }

        
$modules Library::loadLibrary('Modules');
        
$modules->call_hook('user_confirm'$userDetails); // Call any module functions
        
$result->freeResult();
        return 
true;
                                    }
    } 

Last edited by misterp; 03-06-2011 at 04:49 PM.
misterp is offline   Reply With Quote
Old 03-06-2011, 04:58 PM   #6
Developer & Moderator
 
 
Join Date: Jan 2007
Location: Pennsylvania, USA
Posts: 2,147
Rep Power: 63
Mike-N-Tosh is just really nice Mike-N-Tosh is just really nice
Default

It would appear that you are completely misunderstanding what the end user process is here. These are the steps the end user goes through to register.

1. User visits site
2. User clicks on "Register"
3. User submits the registration form
4. User gets redirected to login.tpl

5. User receives in EMAIL welcome email, validation email.
6. Clicks link in the validation email
7. User goes to site via the clicked link (The Register.php function confirm is run!!!)
8. If confirmation validates, user account is activated and they are sent to the userindex.tpl
OR if confirmation is invalid, error and user is redirected to the login page again.

Attempting to login DOES NOT RUN THE CONFIRMATION!

Does that make sense? Only clicking on the validation link in the validation email sends the user to the site and runs the confirmation.
__________________
Mike-N-Tosh
IndianaPC.org - A community website (v3.1.10 Developer - heavily modified & used as the CMS)
Sandbox [localhost(v3.1.10, v4.0.9, 4.1.10,4.2,5.0)] for development and customization
Visit My blog: reviews, tips, tricks, tutorials and my store with Templates, Mods & Docs
Web Hosting | Web Design & Development | 68 Classifieds Customizations
I am not a 68C employee, just a user and try to help out
Mike-N-Tosh is offline   Reply With Quote
Old 03-06-2011, 05:29 PM   #7
Customer
 
Join Date: Mar 2011
Posts: 5
Rep Power: 0
misterp is on a distinguished road
Default

Yes I think thats what I'm working with.... so when the user clicks the link in the confirmation e-mail I want it to set their user group.
I'm only trying to do that at this stage because thats what someone else on the site was doing and it seemed a decent place to run the extra code in this confirm() function.

Is it right that normally this function will check that the confirmation code from the e-mail is right (which it should be if theyve just clicked the link) and changes the user group from 'awaiting confirmation' to 'registered user', but i want at that point to add add functionality that checks my extra2 registration field and sets the user to 'registered user' or 'trader'.

What do you think of this? I would have thought it works but if you try and register it never successfully confirmas the accout, when you click the link in the email you should then be able to log in but it still comes up as this account has not been confirmed (click here to re-send e-mail)
I obviously ballsed up that part but I dont know how.

PHP Code:
function confirm ($confirmCode)
    {
                
        
$sql 'SELECT extra2 FROM' .PREFIX.'users WHERE uVerify = ' $this->_db->quoteInto($confirmCode); 
        
$result =  $this->db->query($sql); 
        
// run my logic  
        
if ( $result->size()==
        { 
            
$exrs $result->fetch(); 
            
$extra2 $result['extra2'];
            if (
$extra2="Traders")
            {
                
$result->freeResult();
                
$sql 'UPDATE ' PREFIX 'users SET level=6 WHERE uVerify=' $this->_db->quoteInto($confirmCode);
                
$result $this->_db->query($sql);
                                
            }
            else
            {
                
$result->freeResult();
                
$sql 'UPDATE ' PREFIX 'users SET level=2 WHERE uVerify=' $this->_db->quoteInto($confirmCode);
                
$result $this->_db->query($sql);
                
                
            }

        
$modules Library::loadLibrary('Modules');
        
$modules->call_hook('user_confirm'$userDetails); // Call any module functions
        
$result->freeResult();
        return 
true;
        }
    } 
misterp is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Registration:Extra field not showing FlyAgain Technical Support 2 01-18-2010 03:51 PM
Moderate ADS from user or group philoo Technical Support 2 12-01-2009 04:40 AM
User registration extra field with multiple selection magicosta Technical Support 4 04-22-2009 10:13 AM
Extra field Drop down list in User Registration hel68c Modules / Plugins / Modifications 3 02-08-2009 07:33 PM
Extra field user join wesse249 Technical Support 4 09-25-2008 02:53 PM


All times are GMT -4. The time now is 06:13 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2011, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0