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)
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: $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.
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?
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: $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: $extraSQL = 'SELECT extra2 FROM' .PREFIX.'users WHERE uVerify = ' . $this->_db->quoteInto($confirmCode); $exresult = $this->db->query($extraSQL); // run my logic if ( $exresult->size()==1 ) { $exrs = $exresult->fetch(); $extra2 = $exresult['extra2']; if ( $extra2 == "2" ) { .....
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: 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; } $extraSQL = 'SELECT extra2 FROM' .PREFIX.'users WHERE uVerify = ' . $this->_db->quoteInto($confirmCode); $exresult = $this->db->query($extraSQL); // run my logic if ( $exresult->size()==1 ) { $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() != 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; } }
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.
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: 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()==1 ) { $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; } }