[Skip to main content](#vessel-content)

#   Using AJAX to load states

##

- **[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")**
- [![GSW00d's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13067-gsw00d "View GSW00d's Profile") Topic Author
- [ Offline](/forum/user/13067-gsw00d)

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 3 months ago -  11 years 3 months ago [\#210609](#210609) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#210609 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")* was created by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")*

-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.4.43

Hi Hika Team!

We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.

Regards,
Bruce Atkinson

Last edit: 11 years 3 months ago by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86555
- Thank you received: 14304
-
-

11 years 3 months ago [\#210612](#210612) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#210612 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

Hi,

The loading of the data and display of the fields is not done in a view. It's done in the file administrator/components/com_hikashop/classes/field.php
So one solution is to do your modifications directly there.
But a cleaner solution is to implement a new type of custom field (that you can have extending from the state type custom field class) via the creation of a HikaShop plugin.
You can see an example of that with the plugin plugins/hikashop/datepickerfield/ and you can see documentation on that in the Fields API section of our developer documentation:
[ www.hikashop.com/support/support/documen...r-documentation.html](http://www.hikashop.com/support/support/documentation/62-hikashop-developer-documentation.html)

The following user(s) said Thank You: [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")**
- [![GSW00d's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13067-gsw00d "View GSW00d's Profile") Topic Author
- [ Offline](/forum/user/13067-gsw00d)

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 2 months ago -  11 years 2 months ago [\#213712](#213712) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  Replied by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#213712 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

Hi!

I've written Joomla friendly ajax code using the select2 library, is there an easy way of bundling this up in a hika plugin so that it will display as a field? I have looked at datepickerfield.php and datepickerfield_class.php and have made custom Joomla plugins in the past.

We are using a custom version of the "states" field in out Hika Database. You can see what we're wanting to integrate via the examples below.

**select.php**Code:

&lt;?php // Get Joomla! framework define( '_JEXEC', 1 ); define( '_JEXEC', 1 ); define('JPATH_BASE', '/path/to/joomla'); require_once ( JPATH_BASE .'/includes/defines.php' ); require_once ( JPATH_BASE .'/includes/framework.php' ); ?&gt; &lt;html&gt; &lt;head&gt; &lt;script src="/t3-assets/js/js-9610a.js?t=123" type="text/javascript"&gt;&lt;/script&gt; &lt;link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" /&gt; &lt;script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function() { jQuery('select').select2(); }); function refresh_area(){ jQuery('#areaBox').html("&lt;option&gt;Select an area&lt;/option").select2({ ajax: { url: 'fetch_data.php', dataType: 'json', delay: 250, data: function (params) { return { q: params.term, // search term country: get_country // call to get_country function }; }, processResults: function (data) { // parse the results into the format expected by Select2. // since we are using custom formatting functions we do not need to // alter the remote JSON data return { results: data }; }, cache: true } }); } function get_country(){ var country = jQuery('#country').val(); return country; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;center&gt; &lt;div&gt; &lt;select id="country" onChange="refresh_area();" style="width: 25%"&gt; &lt;option&gt; Select a country &lt;/option&gt; &lt;?php // open db $app = &amp;JFactory::getApplication('site'); $db =&amp; JFactory::getDbo(); // prepare query $query = $db-&gt;getQuery(true); $query = "SELECT * "; $query .= "FROM &#96;#__hikashop_zone&#96; "; $query .= "WHERE zone_type = 'country' "; $query .= "AND zone_published = 1 "; $query .= "ORDER BY &#96;zone_name_english&#96; ASC"; // fetch the results $db-&gt;setQuery($query); $results = $db-&gt; loadAssocList(); // validate to make sure we have a result and return if(count($results) &gt; 0){ foreach ($results as $result) { echo '&lt;option value="'.$result['zone_namekey'].'"&gt;'.$result['zone_name_english']."&lt;/option&gt;"; } } else { echo '&lt;option&gt;No Country Found&lt;/option&gt;'; } // close database connection $db-&gt;freeResult(); ?&gt; &lt;/select&gt; &lt;/div&gt; &lt;br /&gt; &lt;div&gt; &lt;select id="areaBox" style="width: 25%"&gt; &lt;option&gt; Select an area &lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/center&gt; &lt;/body&gt; &lt;/html&gt;

**fetch\_data.php**Code:

&lt;?php // Get Joomla! framework define( '_JEXEC', 1 ); define( '_JEXEC', 1 ); define('JPATH_BASE', '/path/to/joomla'); require_once ( JPATH_BASE .'/includes/defines.php' ); require_once ( JPATH_BASE .'/includes/framework.php' ); // open db $app = &amp;JFactory::getApplication('site'); $db =&amp; JFactory::getDbo(); // prepare search and country strings $search = strip_tags(trim($_GET['q'])); $country = strip_tags(trim($_GET['country'])); // prepare query $query = $db-&gt;getQuery(true); $query = "SELECT #__hikashop_zone_link.zone_parent_namekey, #__hikashop_zone_link.zone_child_namekey, #__hikashop_zone.zone_namekey, #__hikashop_zone.zone_name_english "; $query .= "FROM &#96;#__hikashop_zone_link&#96; "; $query .= "INNER JOIN &#96;#__hikashop_zone&#96; ON #__hikashop_zone_link.zone_child_namekey = #__hikashop_zone.zone_namekey "; $query .= "AND #__hikashop_zone_link.zone_parent_namekey = '".$db-&gt;escape($country)."' "; $query .= "AND #__hikashop_zone.zone_published = 1 "; $query .= "AND #__hikashop_zone.zone_name_english LIKE '%".$db-&gt;escape($search)."%' "; $query .= "ORDER BY #__hikashop_zone.zone_name_english ASC "; $query .= "LIMIT 40"; // fetch the results $db-&gt;setQuery($query); $results = $db-&gt; loadAssocList(); // validate to make sure we have a result if(count($results) &gt; 0){ foreach ($results as $key =&gt; $value) { $data[] = array('id' =&gt; $value['zone_namekey'], 'text' =&gt; $value['zone_name_english']); } } else { $data[] = array('id' =&gt; '0', 'text' =&gt; 'No Area Found'); } // close database connection $db-&gt;freeResult(); // return the result in json echo json_encode($data); ?&gt;

So what we're looking for is contents for a new plugin named "customzoneajax". Would we install it at './plugins/hikashop/customzoneajax' and what would the contents of files 'customzoneajax.php' and 'customzoneajax_class.php' be?

Last edit: 11 years 2 months ago by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26400
- Thank you received: 4080
-
- [](http://obsi.dev)
-

11 years 2 months ago [\#213745](#213745) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#213745 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

Hi,

We split the plugin custom fields into two files in order to have something light ; so when the field is not required (which is the case in most pages), the class is not loaded.
Like Nicolas told you, the datepicker is today the best example for a plugin custom field ; and when you create your plugin, you can add other PHP files if you want an entry point for the AJAX calls, you can also create a system plugin to be able to catch some Joomla URLs.

Using the plugin system, you can create new kind of custom fields and in these fields, the plugin can display whatever it wants as long as the data can be read in the POST to store a value in the database.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")**
- [![GSW00d's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13067-gsw00d "View GSW00d's Profile") Topic Author
- [ Offline](/forum/user/13067-gsw00d)

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 2 months ago [\#213805](#213805) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  Replied by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#213805 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

Hi Jerome!

That didn't really help me much. Fortunately I discovered a workaround that achieves my needs by doing the following. For those who want to do something similar, this is what I did.

Create 'ajax' folder in joomla root. Saved select2.min.css and select2.min.js to this folder. Disabled chosen library in hikashop configuration. Created custom /ajax/fetch_data.php file as follows: Code:

&lt;?php // Get Joomla! framework define( '_JEXEC', 1 ); define( '_JEXEC', 1 ); define('JPATH_BASE', '/path/to/joomla'); require_once ( JPATH_BASE .'/includes/defines.php' ); require_once ( JPATH_BASE .'/includes/framework.php' ); // open db $app = &amp;JFactory::getApplication('site'); $db =&amp; JFactory::getDbo(); // prepare search and country strings $search = strip_tags(trim($_GET['q'])); $country = strip_tags(trim($_GET['country'])); // prepare query $query = $db-&gt;getQuery(true); $query = "SELECT #__hikashop_zone_link.zone_parent_namekey, #__hikashop_zone_link.zone_child_namekey, #__hikashop_zone.zone_namekey, #__hikashop_zone.zone_name_english "; $query .= "FROM &#96;#__hikashop_zone_link&#96; "; $query .= "INNER JOIN &#96;#__hikashop_zone&#96; ON #__hikashop_zone_link.zone_child_namekey = #__hikashop_zone.zone_namekey "; $query .= "AND #__hikashop_zone_link.zone_parent_namekey = '".$db-&gt;escape($country)."' "; $query .= "AND #__hikashop_zone.zone_published = 1 "; $query .= "AND #__hikashop_zone.zone_name_english LIKE '%".$db-&gt;escape($search)."%' "; $query .= "ORDER BY #__hikashop_zone.zone_name_english ASC "; $query .= "LIMIT 40"; // fetch the results $db-&gt;setQuery($query); $results = $db-&gt; loadAssocList(); // validate to make sure we have a result if(count($results) &gt; 0){ foreach ($results as $key =&gt; $value) { $data[] = array('id' =&gt; $value['zone_namekey'], 'text' =&gt; $value['zone_name_english']); } } else { $data[] = array('id' =&gt; '0', 'text' =&gt; 'No Area Found'); } // close database connection $db-&gt;freeResult(); // return the result in json echo json_encode($data); ?&gt;

Customise address-&gt;show view for front-end as follows:
Code:

&lt;?php /** * @package HikaShop for Joomla! * @version 2.5.0 * @author hikashop.com * @copyright (C) 2010-2015 HIKARI SOFTWARE. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); ?&gt;&lt;?php $name = $this-&gt;type.'_address'; $uniq_id = 'hikashop_address_'.$this-&gt;type.'_'.$this-&gt;address_id; $pfid = ''; if(!empty($this-&gt;fieldset_id)) $pfid = '&amp;fid='.$this-&gt;fieldset_id; else $this-&gt;fieldset_id = $uniq_id; $show_url = 'address&amp;task=show&amp;subtask='.$this-&gt;type.'&amp;cid='.$this-&gt;address_id.$pfid; $save_url = 'address&amp;task=save&amp;subtask='.$this-&gt;type.'&amp;cid='.$this-&gt;address_id.$pfid; $update_url = 'address&amp;task=edit&amp;subtask='.$this-&gt;type.'&amp;cid='.$this-&gt;address_id.$pfid; $delete_url = 'address&amp;task=delete&amp;subtask='.$this-&gt;type.'&amp;cid='.$this-&gt;address_id.'&amp;'.hikashop_getFormToken().'=1'; ?&gt;&lt;div id="&lt;?php echo $uniq_id; ?&gt;"&gt; &lt;?php if(!isset($this-&gt;edit) &#124;&#124; $this-&gt;edit !== true ) { ?&gt; &lt;div class="hika_edit"&gt; &lt;a href="&lt;?php echo hikashop_completeLink($update_url, true);?&gt;" id="&lt;?php echo $uniq_id; ?&gt;_edit" onclick="return window.hikashop.get(this,'&lt;?php echo $this-&gt;fieldset_id; ?&gt;');"&gt;&lt;img src="&lt;?php echo HIKASHOP_IMAGES; ?&gt;edit.png" alt=""/&gt;&lt;span&gt;&lt;?php echo JText::_('HIKA_EDIT'); ?&gt;&lt;/span&gt;&lt;/a&gt; &lt;a href="&lt;?php echo hikashop_completeLink($delete_url, true);?&gt;" id="&lt;?php echo $uniq_id; ?&gt;_delete" onclick="return window.addressMgr.delete(this,&lt;?php echo $this-&gt;address_id; ?&gt;,'&lt;?php echo $uniq_id; ?&gt;','&lt;?php echo $this-&gt;type; ?&gt;');"&gt;&lt;img src="&lt;?php echo HIKASHOP_IMAGES; ?&gt;delete.png" alt=""/&gt;&lt;span&gt;&lt;?php echo JText::_('HIKA_DELETE'); ?&gt;&lt;/span&gt;&lt;/a&gt; &lt;/div&gt; &lt;?php } else { ?&gt; &lt;div class="hika_edit"&gt; &lt;a href="&lt;?php echo hikashop_completeLink($save_url, true);?&gt;" onclick="return window.hikashop.form(this,'&lt;?php echo $this-&gt;fieldset_id; ?&gt;');"&gt;&lt;img src="&lt;?php echo HIKASHOP_IMAGES; ?&gt;ok.png" alt=""/&gt;&lt;span&gt;&lt;?php echo JText::_('HIKA_SAVE'); ?&gt;&lt;/span&gt;&lt;/a&gt; &lt;a href="&lt;?php echo hikashop_completeLink($show_url, true);?&gt;" onclick="return window.hikashop.get(this,'&lt;?php echo $this-&gt;fieldset_id; ?&gt;');"&gt;&lt;img src="&lt;?php echo HIKASHOP_IMAGES; ?&gt;cancel.png" alt=""/&gt;&lt;span&gt;&lt;?php echo JText::_('HIKA_CANCEL'); ?&gt;&lt;/span&gt;&lt;/a&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;?php $display = 'field_backend'; if(isset($this-&gt;edit) &amp;&amp; $this-&gt;edit === true ) { ?&gt; &lt;link href="/ajax/select2.min.css" rel="stylesheet" /&gt; &lt;script src="/ajax/select2.min.js"&gt;&lt;/script&gt; &lt;script&gt; jQuery(document).ready(function() { jQuery('.&lt;?php echo $this-&gt;type;?&gt;_address_country').select2(); jQuery('.&lt;?php echo $this-&gt;type;?&gt;_address_state').select2(); }); function refresh_area(type){ jQuery('.'+type+'_address_state').html('&lt;option value="" id="address_country_" selected="selected"&gt;Please make a selection from the list&lt;/option&gt;').select2({ ajax: { url: '/ajax/fetch_data.php', dataType: 'json', delay: 250, data: function (params) { return { q: params.term, // search term country: get_country(type) // call to get_country function }; }, processResults: function (data) { return { results: data }; }, cache: true } }); } function get_country(type){ var country = jQuery('.'+type+'_address_country').val(); return country; } &lt;/script&gt; &lt;table class="admintable table"&gt; &lt;?php foreach($this-&gt;fields as $field){ if($field-&gt;$display &amp;&amp; $field-&gt;field_namekey != 'address_country' &amp;&amp; $field-&gt;field_namekey != 'address_state'){ $fieldname = $field-&gt;field_namekey; ?&gt; &lt;tr class="hikashop_&lt;?php echo $this-&gt;type;?&gt;_address_&lt;?php echo $fieldname;?&gt;" id="hikashop_&lt;?php echo $this-&gt;type; ?&gt;_address_&lt;?php echo $fieldname; ?&gt;"&gt; &lt;td&gt; &lt;div&gt; &lt;label&gt;&lt;?php echo $this-&gt;fieldsClass-&gt;trans($field-&gt;field_realname);?&gt;&lt;/label&gt; &lt;/div&gt; &lt;?php $onWhat = 'onchange'; if($field-&gt;field_type == 'radio') $onWhat = 'onclick'; $field-&gt;table_name = 'order'; echo $this-&gt;fieldsClass-&gt;display( $field, @$this-&gt;address-&gt;$fieldname, 'data['.$name.']['.$fieldname.']', false, ' ' . $onWhat . '="hikashopToggleFields(this.value,\''.$fieldname.'\',\''.$name.'\',0);"', false, $this-&gt;fields, $this-&gt;address ); ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } } ?&gt; &lt;tr class="hikashop_&lt;?php echo $this-&gt;type;?&gt;_address_address_country" id="hikashop_&lt;?php echo $this-&gt;type; ?&gt;_address_address_country"&gt; &lt;td&gt; &lt;div&gt; &lt;label&gt;Country&lt;/label&gt; &lt;/div&gt; &lt;span class="data_billing_address_address_state_container'"&gt;&lt;select id="address_country" onChange="refresh_area('&lt;?php echo $this-&gt;type;?&gt;');" class="hikashop_field_dropdown &lt;?php echo $this-&gt;type;?&gt;_address_country" name="data[&lt;?php echo $this-&gt;type;?&gt;_address][address_country]" style="width: 96%"&gt; &lt;option value="" id="address_country_" selected="selected"&gt;Please make a selection from the list&lt;/option&gt; &lt;?php // open db $app = &amp;JFactory::getApplication('site'); $db =&amp; JFactory::getDbo(); // prepare query $query = $db-&gt;getQuery(true); $query = "SELECT * "; $query .= "FROM &#96;#__hikashop_zone&#96; "; $query .= "WHERE zone_type = 'country' "; $query .= "AND zone_published = 1 "; $query .= "ORDER BY &#96;zone_name_english&#96; ASC"; // fetch the results $db-&gt;setQuery($query); $results = $db-&gt; loadAssocList(); // validate to make sure we have a result and return if(count($results) &gt; 0){ foreach ($results as $result) { echo '&lt;option value="'.$result['zone_namekey'].'" id="address_country_'.$result['zone_namekey'].'"&gt;'.$result['zone_name_english']."&lt;/option&gt;"; } } else { echo '&lt;option&gt;No Country Found&lt;/option&gt;'; } // close database connection $db-&gt;freeResult(); ?&gt; &lt;/select&gt;&lt;/span&gt; &lt;span class="hikashop_field_required"&gt;*&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr class="hikashop_&lt;?php echo $this-&gt;type;?&gt;_address_address_state" id="hikashop_&lt;?php echo $this-&gt;type; ?&gt;_address_address_state"&gt; &lt;td&gt; &lt;div&gt; &lt;label&gt;City/Suburb/Area&lt;/label&gt; &lt;/div&gt; &lt;span id="data_&lt;?php echo $this-&gt;type;?&gt;_address_address_state_container"&gt; &lt;select id="data_&lt;?php echo $this-&gt;type;?&gt;_address_address_state" class="hikashop_field_dropdown &lt;?php echo $this-&gt;type;?&gt;_address_state" name="data[&lt;?php echo $this-&gt;type;?&gt;_address][address_state]" style="width: 96%"&gt; &lt;option value="" id="data_&lt;?php echo $this-&gt;type;?&gt;_address_address_state_" selected="selected"&gt;Please make a selection from the list&lt;/option&gt; &lt;/select&gt; &lt;/span&gt; &lt;input type="hidden" id="data_&lt;?php echo $this-&gt;type;?&gt;_address_address_state_default_value" name="data_&lt;?php echo $this-&gt;type;?&gt;_address_address_state_default_value" value=""&gt; &lt;span class="hikashop_field_required"&gt;*&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php } else { if(false) { ?&gt; &lt;table class="admintable table"&gt; &lt;?php foreach($this-&gt;fields as $field){ if($field-&gt;$display){ $fieldname = $field-&gt;field_namekey; ?&gt; &lt;tr class="hikashop_&lt;?php echo $this-&gt;type;?&gt;order_address_&lt;?php echo $fieldname;?&gt;"&gt; &lt;td class="key"&gt;&lt;label&gt;&lt;?php echo $this-&gt;fieldsClass-&gt;trans($field-&gt;field_realname);?&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;&lt;?php echo $this-&gt;fieldsClass-&gt;show($field, @$this-&gt;address-&gt;$fieldname);?&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } } ?&gt; &lt;/table&gt; &lt;?php } else { ?&gt; &lt;div class="hikashop_address_content" onclick="return window.addressMgr.click(this,&lt;?php echo $this-&gt;address_id;?&gt;,'&lt;?php echo $uniq_id; ?&gt;','&lt;?php echo $this-&gt;type; ?&gt;');"&gt; &lt;?php if(empty($this-&gt;addressClass)) $this-&gt;addressClass = hikashop_get('class.address'); echo $this-&gt;addressClass-&gt;displayAddress($this-&gt;fields,$this-&gt;address,'address'); ?&gt; &lt;/div&gt; &lt;?php } } if(isset($this-&gt;edit) &amp;&amp; $this-&gt;edit === true) { echo '&lt;input type="hidden" name="data['.$name.'][address_id]" value="'.$this-&gt;address_id.'"/&gt;'; echo JHTML::_( 'form.token' ); } ?&gt; &lt;script type="text/javascript"&gt; if(!window.addressMgr) window.addressMgr = {}; window.addressMgr.update&lt;?php echo ucfirst($this-&gt;type);?&gt; = function() { window.Oby.xRequest('&lt;?php echo hikashop_completeLink('address&amp;task=show&amp;subtask='.$this-&gt;type.'_address&amp;cid='.$this-&gt;address_id, true, false, true); ?&gt;',{update:'&lt;?php echo $this-&gt;fieldset_id; ?&gt;'}); }; &lt;?php static $hikashop_address_show_js_init = false; if(!$hikashop_address_show_js_init) { $hikashop_address_show_js_init = true; ?&gt; window.addressMgr.delete = function(el, cid, uid, type) { if(!confirm('&lt;?php echo JText::_('HIKASHOP_CONFIRM_DELETE_ADDRESS', true); ?&gt;')) return false; var w = window, o = w.Oby, d = document; o.xRequest(el.href, null, function(xhr) { if(xhr.status == 200) { if(xhr.responseText == '1') { var target = d.getElementById(uid); if(target) target.parentNode.removeChild(target); window.Oby.fireAjax('hikashop_address_deleted',{'type':type,'cid':cid,'uid':uid,'el':el}); } else if(xhr.responseText != '0') o.updateElem(uid, xhr.responseText); }}); return false; }; window.addressMgr.click = function(el, cid, uid, type) { window.Oby.fireAjax('hikashop_address_click',{'type':type,'cid':cid,'uid':uid,'el':el}); } &lt;?php } if(JRequest::getVar('tmpl', '') == 'component') { if(empty($this-&gt;addressClass)) $this-&gt;addressClass = hikashop_get('class.address'); $miniFormat = $this-&gt;addressClass-&gt;miniFormat($this-&gt;address); ?&gt; window.Oby.fireAjax('hikashop_address_changed',{'type':'&lt;?php echo $this-&gt;type; ?&gt;','edit':&lt;?php echo $this-&gt;edit?'1':'0'; ?&gt;,'cid':&lt;?php echo $this-&gt;address_id; ?&gt;,'miniFormat':'&lt;?php echo str_replace('\'','\\\'', $miniFormat); ?&gt;'&lt;?php $previous_id = JRequest::getVar('previous_cid', null); if((!empty($previous_id) &#124;&#124; $previous_id === 0) &amp;&amp; is_int($previous_id)) echo ',\'previous_cid\':' . $previous_id; ?&gt;}); &lt;?php echo $this-&gt;init_js; } ?&gt; &lt;/script&gt; &lt;/div&gt;

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")**
- [![GSW00d's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13067-gsw00d "View GSW00d's Profile") Topic Author
- [ Offline](/forum/user/13067-gsw00d)

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 2 months ago [\#214127](#214127) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  Replied by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#214127 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

There is one addition that will really help though, how might I auto-load the country and state in the users current address?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86555
- Thank you received: 14304
-
-

11 years 2 months ago [\#214136](#214136) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#214136 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

Hi,

Could you give more context on what you're trying to do ?
Because the states and countries are already loaded for the addresses in HikaShop.
So I don't understand what you're trying to do where and why.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")**
- [![GSW00d's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13067-gsw00d "View GSW00d's Profile") Topic Author
- [ Offline](/forum/user/13067-gsw00d)

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 1 month ago [\#214191](#214191) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  Replied by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#214191 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

Hi Nicolas!

We've had to do some tweaks as we've been growing with Hikashop over the years, one of which was using the states field for a whole bunch of areas (around 6000). Due to the size of this list, I needed to populate the select field via ajax, which I've done by customising the Address-&gt;Show view for front-end. I was able to bypass the fields class by using this condition Code:

if($field-&gt;$display &amp;&amp; $field-&gt;field_namekey != 'address_country' &amp;&amp; $field-&gt;field_namekey != 'address_state')

Everything is working nicely now, except the country and state fields I've bypassed won't load their stored values if the customer is editing their address, seeing as I've bypassed the code in the fields class that does this. What I'm hoping for is the sql/programming logic that would allow me to leverage this from the address-show view.

So in summary, how could I 'echo' the customer's selected addresses' country and state as a string from the address-&gt;show view.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26400
- Thank you received: 4080
-
- [](http://obsi.dev)
-

11 years 1 month ago [\#214247](#214247) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#214247 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

Hi,

The zone custom field has not been designed to be overridden.
If you want to customize the zone custom field with your own data and own process ; the best will be to create a new kind of custom field using a custom plugin ; like the "advanced date picker".
Just like I wrote in a previous message

> Using the plugin system, you can create new kind of custom fields and in these fields, the plugin can display whatever it wants as long as the data can be read in the POST to store a value in the database.

We are not able to help you for the loading of your data for the zone custom field because it has not been design to support it ; it is a too important modification of the field.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

The following user(s) said Thank You: [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")**
- [![GSW00d's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/13067-gsw00d "View GSW00d's Profile") Topic Author
- [ Offline](/forum/user/13067-gsw00d)

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 1 month ago [\#214352](#214352) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  Replied by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#214352 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

Thanks Jerome! I understand it is risky.

Is there an easy way to get the users's address info from the address-&gt;show view?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86555
- Thank you received: 14304
-
-

11 years 1 month ago [\#214361](#214361) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Using AJAX to load states](/forum/28-shipping-methods/878583-using-ajax-to-load-states#214361 "-- HikaShop version -- : 2.5.0 -- Joomla version -- : 3.4.1 -- PHP version -- : 5.4.43  Hi Hika Team!  We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.  Regards, Bruce Atkinson")*

Sure:
- get the current user_id with a call to the function hikashop_loadUser()
- do a MySQL on the hikashop_address table where the address_user_id is equal to that user_id

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI4LXNoaXBwaW5nLW1ldGhvZHMvODc4NTgzLXVzaW5nLWFqYXgtdG8tbG9hZC1zdGF0ZXM/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.090 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
