NYCPHP Meetup

NYPHP.org

[joomla] Removing name field from user registration

Gary Mort garyamort at gmail.com
Tue May 25 10:38:30 EDT 2010


On Mon, May 24, 2010 at 1:37 PM, Chris TheEnd <chris at theendrecords.com>wrote:

> Yea just do an HTML override for the register component in your template
> html folder and you are good to go.
>

Actuslly, only if you are making the username field hidden and filled in
with a predefined value..  I've discovered something "new" while doing hacks
of K2[cloning it to have 2 versions installed, K2 and K3, and making mods to
one].

Most Joomla applications use children of JTable classes to define MySQL
table structures.

One of the things that you can do when using this class, is add extra
validations in those tables themselves.

So Mark, I was completely offbase here on my suggestion.  After doing a
little extra digging, I find that in
libraries/joomla/database/table/user.php there is a function called "check"
starting at line 136 in the version of Joomla installed on a server I am
currently working with.

Lines 141-144 are the check on the users full name,
// Validate user information
if (trim( $this->name ) == '') {
 $this->setError( JText::_( 'Please enter your name.' ) );
return false;
 }

The positive of doing things in this manner is that instead of spreading
validations throughout the code in every place a user can be updated or
created, it is in one function and all those places can call it.

The downside is you are well and truly stuck in that you either HAVE to hack
the core code to remove this check OR you have to completely duplicate the
user module to fix this.

Note, there is a way to "hack" the core code without actually hacking it.
 Joomla is "smart" about including class definition files, when they are
included using the Joomla Loader, Joomla will first check to see if the
class exists, if it exists it won't load the file a second time.

As such, if you can setup Joomla in such a way as to "beat" the system to
including a class file and include your OWN version of the class file, you
can override/trick Joomla into using your file instead.  That's what I did
with the plugin to display HTML comments with the template filename before
and after every view template that is loaded as a way of tracking down which
templates are being used in my plugin:
http://gothaminformatics.com/our-extensions/corehack-debugging-plugin

It is a system plugin that has to be set to the very very top of the system
plugin loads, and it will grab the Joomla loader class file, dynamically
modify it with my code and save it to a temp directory, and then include it.
 Thus beating the system and getting there first[I did the whole dynamic
thing so if that file is changed in some way upon future upgrade, even with
the plugin enabled you would still be using the latest code... If you are
planning on running this /all/ the time as opposed to when debugging/testing
than you should save a copy of the user.php file above and use that instead
of dynamic hacking....  you could even include a subdirectory for every
version of joomla and include a version specific user.php table file, and if
there is no version specific file, then let Joomla use the base one and send
an email to the system admin to remind him that he needs to update the
plugin.]

At least, that is the way I would code it and set it up if I was being paid
to code such a plugin. :-)

-Gary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/joomla/attachments/20100525/eab11a8d/attachment.html>


More information about the Joomla mailing list