Wednesday, October 07, 2009

User Login Custom Processing

Having aded some fields previously, i now need to perform some custom actions.

What i need to do is manage the usertype column population.

To do that, we modify the com_user controller. (components/com_user/controller.php).

We modify the 'register_save' function.


(line 237)
$post = JRequest::get('post');
$user->set( 'name' , $post['title']." ".$post['firstname']." ".$post['middlenames']." ".$post['surname'] );
$usertype2 = $post['usertype2'];

...

(line 269)
if ($usertype2 == 'photographer')
{
$user->set('usertype', 'Author');
}
elseif ($usertype2 == 'consumer')
{
$user->set('usertype', 'Registered');
}
else
{
$user->set('usertype', $newUsertype);
}


Also, i want to stop checking of the 'name' field as i am using other fields to populate this. To do that amend libraries/joomla/database/table/user.php
, commenting out this section (line 152):

if (trim( $this->name ) == '') {
$this->setError( JText::_( 'Please enter your name.' ) );
return false;
}



Next
Next step is to amend the form so that depending upon which user type i pick, hide some of the fields.

Update
Ok, can now hide a field on the registration form based on the value of a a drop down.

Added this javascript:

function hideFields()
{
var x=document.getElementById("usertype2");
if (x.value == 'consumer')
{
document.getElementById("biographyrow").style.display='none';
}
else
{
document.getElementById("biographyrow").style.display='block';
}
}


So, when the user amends a drop-down called 'usertype2' (onchange event), the above is called.

You need to make sure that the row which holds the field has the id 'biographyrow' (in this case).

No comments: