Possible to Set Dropdown value based on IP Address

eugenecjr

Member
I have users in several locations and each location has a static IP. We have several forms where they enter the location, in this case a store number. From time to time users enter the wrong location. I am wondering if it would be possible to capture the locations IP address and use that to set a dropdown to a specific value. Eliminating the need to set this value on various forms. One where they may enter up to 20-30 values a day.
 
In PHP you can get the client's IP address with e.g. $_SERVER['REMOTE_ADDR'].
So, the simplest would probably be to use a calc element to do so and return the location (or store number, respectively) depending on IP.
 
There's also a Fabrik element 'ip' which stores the user's IP.
Which may or may not be useful, I don't know if it's fetched on form load...
 
I wouldn't bother with a calc element. Simply load/revise the drop down list in the elements advanced php section.
 
achartier, I really like the idea of just limiting the list based on location (IP). This would allow the list to remain unaltered if you are at any location other then one specified. I know that I sometimes need to make entries while offsite and need to be able to select the respective location. I am now looking for information to familiarize myself with this.
 
achartier, I have been trying on and off for a couple days now to put this together using Advanced Eval Options. I have gone through just about every post that mentions Eval Options and still not getting there. I basically and trying to use $_SERVER['HTTP_X_FORWARDED_FOR'] and have a an element called ip_address within the table being used with the databasejoin element. Value set to ID, Label set to Store. The database that contains these values along with the ip_address is fab_stores.

Looking to have the dropdown only show the store that has the ip_address that = $_SERVER['HTTP_X_FORWARDED_FOR'].

Bonus would be to then have this setup so that if $_SERVER['HTTP_X_FORWARDED_FOR'] is not one of the ip_address then show all options.

Thank you in advance for your assistance.
 
You are using the Advanced tab, Eval Populate section, yes? Can you post what you have in there right now?
 
That is correct, here is what I have right now:

PHP:
$value = $opt->value;
$ip = '{fab_inventory_196_repeat___client_ip}';
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
    ->select('ip_address')
    ->from('fab_stores');
$db->setQuery($query);
$column= $db->loadColumn();

if (in_array($ip, $column, true)) {
$opt->disable = true;
}

My understanding is that the code is to be iterated through for each option. What I have here is a butchered version of of several attempts to try different things.
 
troester,

I apologize, I did not catch the switch, I am working in Eval Options which is where I believe I should be if I am looking to disable certain items in the list if they do not apply. I simple am not able to get this setup such that the IP address returned from fab_inventory_196_repeat___client_ip is compared to ip_address of fab_stores which is the table being used with the databasejoin element. I have read the wiki over and over and am missing something that is likely obvious but just not to me.
 
As Troester rightly states, in the Eval you must create all the options. It seems like you are expecting the code to run for each option assuming the option is input to the Eval when it is not. His pointer to the Wiki shows you the correct way to do it.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top