Question

I am using a joomla module i would like to modify to auto load the default list of results.

currently, when the page loads no result is shown. If all search fields are empty and the user clicks the search button, the page will load all data. If information in placed in the search fields, the results will be broken down to match what was typed in.

I want the page to auto load all data when the page loads without the user clicking search. How do i achieve this?

I believe the module uses ajax and i believe the info that affects this is below:

<?php 

    header('Access-Control-Allow-Origin: *');
    header('Content-Type: text/html');

    define('_JEXEC', 1);
    define('DS', DIRECTORY_SEPARATOR);

    ini_set("display_errors", "On");
    error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING);

    $my_path = dirname(__FILE__);
    $my_path = explode(DS.'modules',$my_path);  
    $my_path = $my_path[0];         

    if (file_exists($my_path . '/defines.php')) {
        include_once $my_path . '/defines.php';
    }

    if (!defined('_JDEFINES')) {
        define('JPATH_BASE', $my_path);
        require_once JPATH_BASE.'/includes/defines.php';
    }

    require_once JPATH_BASE.'/includes/framework.php';
    $app = JFactory::getApplication('site');
    $app->initialise();

    ///////////////////////////////////////////////////////////////////////////////////////////////

    $name = $_GET['name'];
    $value = mb_strtolower($_GET['value']);
    $next = mb_strtolower($_GET['next']);

    $db = JFactory::getDBO();
    $query = "SELECT * FROM #__k2_extra_fields WHERE published = 1";

    $db->setQuery($query);
    $results = $db->loadObjectList();

    $extra_val = '';
    $extra_id = 0;
    foreach($results as $result) {
        if(trim(mb_strtolower($result->name)) == trim($value) . " " . trim($next) || trim(mb_strtolower($result->name)) == trim($next) . " " . trim($value)) {
            $extra_val = $result->value;
            $extra_id = $result->id;
            break;
        }
    }

    require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'JSON.php');
    $json = new Services_JSON;
    $extra_val = $json->decode($extra_val);

    if($extra_val != '') {
        foreach($extra_val as $val) {
            echo "<option>" . $val->name . "</option>";
        }
        echo "<option>".$extra_id."</option>";
    }

?>

Please help!

Was it helpful?

Solution

to auto load search result we must need to store search query in session variable,

http://docs.joomla.org/How_to_use_user_state_variables

http://docs.joomla.org/API15:JApplication/getUserStateFromRequest

This are the links which will describe very well about how to manage request variable in session, so there is no variable in request it will get value from the session.

OTHER TIPS

try to use something like this

<html>
<head>
<script>
function myFunction()
{
alert("Page is loaded");
}
</script>
</head>

<body onload="myFunction()">
<h1>Hello World!</h1>
</body>

</html>

then you can easily change myFunction to trigger your search on click event

<script>
function myFunction()
{
   document.getElementById('YOUR-BUTTON-ID').onclick();
}
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top