views:

577

answers:

5

i m developing site in Joomla, meanwhile i stuck in a problem,please help me in below problem

here is my folder structure for component

htdocs/Joomla/administrator/component/com_test/test.php,controller.php
                                              models/test.php
                                              controllers/test.php
                                              views/test/view.html.php
                                              view/test/tmpl/default.php

now in view.html.php i created a form where i m using jquery ajax code for usernmae availability check

but i m not getting how do i combine all things to get the result that usename is available or not

here is my code written on test/view.html.php

<script type="text/javascript">
 jQuery(document).ready(function(){
 jQuery("#username").change(function () {
    var usr = jQuery("#username").val();
    if (usr.length >= 2) {
     jQuery("#status").html('<img src="loader.gif" align="absmiddle">&nbsp;Checking availability...');
     jQuery.ajax({
         type: "POST",
         url: "index.php?option=com_test&view=check_user",
         data: "username=" + usr,
         success: function (msg) {
         jQuery("#status").ajaxComplete(function (event, request, settings) {
         if (msg == 'OK') {
            jQuery("#username").removeClass('object_error'); // if necessary
                jQuery("#username").addClass("object_ok");
         }
         else {
               jQuery("#username").removeClass('object_ok'); // if necessary
               jQuery("#username").addClass("object_error");
               jQuery(this).html(msg);
         }
       });
      }
    });
  }    
});

<script>

<form action="" method="post" name="addUserForm" id="addUserForm" > 
   <table width="100%" border="0" cellpadding="4" cellspacing="2">
     <tr>
    <th >User Name :</th>
        <td ><input type="text" name="username" id="username" size="50">
             <span id="status"></span>  
        </td>
     </tr>      
   </table>
</form>

i have created below folders structure for above action , please tell me where do i mistake

view/check_user/view.html.php
views/check_user/tmpl/default.php

code in check_user/view.html.php

<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the advertising component
 */
class TestViewCheck_user extends JView 
{
   /**
    * Default display function
    */  
    function display($tpl = null) 
    {
        $testController = new TestController();
        // Make an object of Main Model class contains Main functions
        $testModel = $testController->getModel('test');
        $userName  = JRequest::getVar('username');
        parent::display($tpl);
        }
 }
?>

but when i run this code...why http://localhost/Joomla/includes/js/joomla.javascript.js file runs infinite times.. and finally give 4 error

now what i have to modify/add more??? please just guide me ....

refer any useful link which teach to create component step by step ...it will be very helpful for me

Thanks a lot

A: 

All front end code should be in your tmpl, so your Ajax stuff should be in there too. Check this tutorial out on how to make MVC components for Joomla http://www.joomladevuser.com/tutorials/components.

Martin
@Martin Thank you for link
JustLearn
A: 

Hello dears; 1-you must copy your main index.php in root of joomla and paste with new name of ajax.php or something you like. 2-in this file you must disable ...->render(); method and replace a method that renders partial views to your output;

my problem := what is this method that renders partial view;

thank you very much

muhammad sherafat
A: 

Hello Again I found the solution:

1- copy main index.php(joomlaRoot/index.php) of joomla and rename it to any name (forexample joomlaRoot/ajax.php);

2- disable render method ($mainframe->render();)

3- copy this code under the render method line ==

/*/ $document =& JFactory::getDocument(); $content=$document->getBuffer(); foreach($content as $var){ foreach($var as $var2){ echo $var2; } }

/**/

muhammad sherafat
A: 

sorry I forget the rest of document

you must call ajax.php for ajax requests such as wwww.example.com/ajax.php?option=com_componentexample&task=ajaxtask

and for submits and links index.php====

wwww.example.com/index.php?option=com_componentexample&task=submittask

muhammad sherafat