niedziela, 29 stycznia 2012

Joomla 1.5 Extended Registration

What if you need something more than the default registration form in Joomla? Like for instance adding mobile phone validation, zip code and many more custom fields. Then you could make your own component that extends the functionality of the normal default user component and that is what this tutorial is all about.

Quick how to:

1.) Start with copying the current com_user folder and name it com_extendeduser, edit the xml description file to reflect the changes.

2.) Make an sql file with the sql needed to create the new table jos_extuser. Zip it up and install in the Joomla backend.

3.) It’s time to start coding. We start by making an extension to JTable in the models folder of our new component, we call the class TableExtUser and it should contain member variables that match the field names in the database exactly. All except the password which we call $_password. Next we add some methods, many are extensions to the JTable.

4.) Next we create some display functions to make the view file look as clean as possible. It will be a kind of poor man’s Smarty. Anyway we create these utility functions in the view.html.php file in the register folder.

5.) Now we can edit the default.php file in register/tmpl/ and use our newly created display functions. We also create some new views, for instance a form where the user is prompted to enter a valid code which she should have gotten as an SMS to her phone.

6.) Then we modify the controller in controller.php. This is done mainly by working with the register_save() function in order to save to our new extended user table as well as to the default user table. We also add a few functions and change in some more places. To see everything you could use kdiff and examine how the file in our new component differs from the equivalent in com_user.

7.) Finally we create a new login module called mod_extlogin which basically is just a tiny mod of mod_login in order to route some stuff to our extuser component instead of the normal user component.

8.) Now you are ready to use your new fancy registration form while at the same time letting the out of the box code do as much as it can. A big example is email validation which we just left to the default logic of Joomla.

9.) Optional: Drop necessary language files in the com_extendeduser folder.

I hope this will help all you people who are thinking about charging people for high quality content through their mobile phones.

What is PHP?

PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. It is among one of the first developed server-side scripting languages to be embedded into an HTML source document, rather than calling an external file to process data. Ultimately, the code is interpreted by a web server with a PHP processor module which generates the resulting web page. It also has evolved to include a command-line interface capability and can be used in standalone graphical applications.PHP can be deployed on most web servers and also as a standalone shell on almost every operating system and platform free of charge. A competitor to Microsoft's Active Server Pages (ASP) server-side script engine and similar languages, PHP is installed on more than 20 million websites and 1 million web servers.

PHP was originally created by Rasmus Lerdorf in 1995. The main implementation of PHP is now produced by The PHP Group and serves as the formal reference to the PHP language. PHP is free software released under the PHP License, which is incompatible with the GNU General Public License (GPL) due to restrictions on the usage of the term PHP.

While PHP originally stood for "Personal Home Page", it is now said to stand for "PHP: Hypertext Preprocessor", a recursive acronym.