Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
send request from Javascript in default.php into helper file, Joomla

I have a fully working module in Joomla, but I'm struggling with the last piece which is sending a value from Javascript in my default.php file into the helper file, where it will be used in a sql query and return the results. Everything up to that point works perfectly and if I just hardcode the value in SQL it returns what I need to the default.php file.

My issue is that when the JS function getApi is called and I set an input value to 12345, I also want to send that value of 12345 into my helpepr function called getStores

How can I properly send this value and have it returned in real time asynchronously?

helper.php

<?php

class modTestHelper
{

public static function getStores($zip)
{
    $db = JFactory::getDBO();
    $user = JFactory::getUser();
    
    $app = JFactory::getApplication();
    $lang = JFactory::getLanguage();
    $date = JFactory::getDate();
    $now = $date->format('Y-m-d');
    
    
    $query = 'SELECT
            name,
            phone,
            address,
            city,
            state,
            zip,
            country,
            url,
            logo,
            lat,
            lng

            from #__loc_table
            where published = 1
            AND zip ="'.$zip.'"';
    
    
    $db->setQuery($query);
    $item=$db->loadObjectList();
    $stores = [
        'type' => 'FeatureCollection',
        'features' => array_map(function($i) {
            return [
                'type' => 'Feature',
                'geometry' => [
                    'type' => 'Point',
                    'coordinates' => [
                        $i->lat,
                        $i->lng
                    ]
                ],
                'properties' => [
                    'storeImage' => $i->logo,
                    'storeName' => $i->name,
                    'phoneFormatted' => $i->phone,
                    'address' => $i->address,
                    'city' => $i->city,
                    'country' => $i->country,
                    'postalCode' => $i->zip,
                    'state' => $i->state
                ]
            ];
        }, $item)
    ];                      
            
    return json_encode($stores);
}
}

mod_test.php

<?php 
 defined('_JEXEC') or die;
require_once dirname(__FILE__) . '/helper.php';

$test = modTestHelper::getStores();


require JModuleHelper::getLayoutPath('mod_test', $params->get('layout', 'default'));
?>

default.php

    <script type="text/javascript">

          function getApi() {
             var zip = '12345';
             div.value = var;
          }

     </script>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!