Home > DeveloperSection > Beginner > Creating Custom Module in Joomla

Creating Custom Module in Joomla


Joomla Joomla 
Ratings:
1 Comment(s)
 5451  View(s)
Rate this:

Creating Custom Module in Joomla

The Module Manager will display the screen where you could add and edit Joomla Modules such as Menu Module, Banner Module, Login Module and Breadcrumbs etc. In Joomla, Modules are used to display content and/or media around the main content.

There are lots of module has been installed with default template in joomla software, which you could use in your default template or customize template at specified position. But in any case if you want to make your own customize module to perform any specific task then you have to perform some following steps.

1.       You have to create two files: PHP file and XML file for module

2.       Upload zip folder of module files

Steps 1: Creating PHP and XML file

Before creating these files you have to follow up a certain formatting.

First of all create a directory with name mod_customizelogin (here I am creating customize login form). Now, you have to create two file with mod_customizelogin.php and mod_customizelogin.xml name and put these files within mod_customizelogin directory.

Here, I am creating customize login form. To create customize login form, write down following codes.

‘mod_customizelogin.php’ Code:

 

        <?php

          global $error, $count,$myusername ;

            include("mod_Config.php");

          

           if($_SERVER["REQUEST_METHOD"] == "POST")

            {

                // username and password sent from Form

                // Store username and password from From  

                $myusername= ($_POST['username']);

                $mypassword=($_POST['password']);

                

                if($myusername == null || $mypassword == null)

                {

                    $error ="Plaese! fill all enteries";

                }

                else

                {

                    // Check username and password in database table

                    $sql="SELECT id FROM dbmyjoomla.lolt9_users WHERE username='$myusername' and password='$mypassword'";

                    // Create qurey in mysql

                    $result=mysql_query($sql);

                    // fetch specified record

                    $row=mysql_fetch_array($result);

                    $active=$row['active'];

 

                    // Count number of rows in result

                    $count=mysql_num_rows($result);

 

                    // If result matched $myusername and $mypassword, table row must be 1 row

                    if($count==1)

                    {

                        session_register("myusername");

                        $_SESSION['login_user']=$myusername;

 

                        header("location:http://localhost/Joomla17/");

                    }

                    else

                    {

                      $error ="Your UserName or Password is invalid";

 

                    }

                }

               }

      ?>

       

   <?php

      echo '<head>';

     echo '<link href="css/login.css" type="text/css" rel="stylesheet"></link>';

     echo '</head>';

      ?>

        <form action="mod_customlogin.php" method="post">

           

            <div id="login">

                <div class="lflogo"> <img src="Images/Clogo.png"></img></div>

                        <table id="tblLogin">

 

                            <tr>

                                <td>

                                   <label>UserName :</label>   

                                </td>

                                <td>

                                   <input type="text" name="username"/>   

                                </td>

                            </tr>

                                <tr>

                                    <td>

                                        <label>Password :</label>

                                    </td>

                                    <td>

                                          <input type="password" name="password"/>

                                    </td>

                                </tr>

                               

                                   

                                <tr> <td class="button">

                                        <input id="btnTd" type="submit" value=" Login " onclick="return fvalidation()"/>

                                    </td>

                                    <td><input type="checkbox"></input>   <label>Remember Me</label> </td>

                                </tr>

                                    

                               

                        </table>

                <div id="footer">

                    <table>

                        <tr>

                            <td> <a href=""> Forgot Password?</a> </td>

                            <td><a href="">Create An Account!</a></td>

                        </tr>

                    </table>

                </div>

                <div id="msgError">  <label><?php echo $error; ?></label>  </div>

                </div>

        </form>

   

 

 

‘mod_Config.php’ Code:

<?php

   /* localhost server information  */

    $mysql_hostname = "localhost"; /*localhost name */

    $mysql_user = "root";

    $mysql_password = "root";

    $mysql_database = "dbmyjoomla";   /* Your database name  */

 

    // creating connection with database

    $con = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)

    or die("Opps connection cannot be establish");

    // select database from mysql

    mysql_select_db($mysql_database, $con) or die("Opps database could not be connected");

?>

‘mod_CheckSession.php’ Code:

<?php

  // include database config file

    include('mod_Config.php');

    //start session

    session_start();

    // assign login user name

    $user_check=$_SESSION['login_user'];

    // select username from joomla table

    $ses_sql=mysql_query("select username from dbmyjoomla.lolt9_users where username='$user_check' ");

    // retrieve selected row from database table

    $row=mysql_fetch_array($ses_sql);

    // assign login username

    $login_session=$row['username'];

    // check person in session

    if(!isset($login_session))

    {

     header("Location: login.php"); // redirect into login page if session is timeout

    }

?>

 

‘mod_logout.php’ Code:

<?php

    session_start();

    // if session is time out then session will be destryed and page redirect to login page

    if(session_destroy())

    {

      header("Location: login.php"); // page redirect into login page

    }

?>

‘mod_customlogin.xml’ Code:

‘mod_customlogin.xml’ uses in joomla software like an installer file for module. So you have to careful about this file at creating time.

Let’s take a look of ‘mod_customlogin.xml’ file code.

‘mod_customlogin.xml’ code:

  <?xml version="1.0" ?>

<!DOCTYPE install PUBLIC "-//Joomla! 1.7//DTD module 1.0//EN" "http://dev.joomla.org/xml/1.5/module-install.dtd"> 

<install version="1.7" type="module">

 

    <name>Custom Login Form</name>

    <creationDate>01/02/2012</creationDate>

    <author>Arun Kumar Singh</author>

    <copyright>This module is released under the mindstick License</copyright>

    <authorEmail>arun_xyz@domain.com</authorEmail>

    <authorUrl>http://mindstick.com</authorUrl>

    <version>1.0</version>

    <description> Login Form Module</description>

     <files>

         <filename module="mod_customlogin">mod_customlogin.php</filename>

         <filename module="mod_customlogin">mod_CheckSession.php</filename>

         <filename module="mod_customlogin">mod_Config.php</filename>

         <filename module="mod_customlogin">mod_logout.php</filename>

         <filename module="mod_customlogin">mod_customlogin.xml</filename>

         <folder>css</folder>

         <folder>Images</folder>

     </files>

    

</install>

 

Now your first step has been completed and proceeds for second step.

Step 2: Uploading zip file in Joomla Software

To upload ‘mod_customlogin’ file in Joomla Software, first of all you have to login in Joomla Administrator Panel.

Creating Custom Module in Joomla

Now go to Extensions -> Extension Manager.

Creating Custom Module in Joomla

To browse and upload file into joomla software, click on Install tab and browse your file which would you want to upload in Joomla Software by clicking on ‘Browse’ button.

Creating Custom Module in Joomla

Creating Custom Module in Joomla

Now click on ‘Upload & Install’ button which is beside on ‘Browse’ button.

Creating Custom Module in Joomla

 Now ‘mod_customlogin’ module is successfully uploaded in Joomla software and it is ready to use in joomla template or joomla software.

But before using custom module in joomla template, first of all you have to perform some setting for custom module to perform this task, go to Extensions -> Module Manager

Creating Custom Module in Joomla

This screen will be display your uploaded customized module, now select your uploaded module by checking adjacent checkbox and click on ‘Edit’ button which is at top right in panel.

This screen will display you to edit some information’s; here you have to edit some information such as Positions, Status, Start Publishing Date, Finish Publishing Date and module assignment.

Fill all appropriate information in fields and click ‘Save & Close’ button.

Creating Custom Module in Joomla

Now your module has been showing in web pages at specified position.

Creating Custom Module in Joomla

So, this is the complete description on how to create customize module in joomla software. I hope it might be helpful for you.


Missing information

By Manihs Kumar on   one year ago
css and images folder are missing in this article.

Don't want to miss updates? Please click the below button!

Follow MindStick