make an element a cookie

I have an a form for registered users, I would like an element in that form to be saved a cookie that will stick with the logged in user while they are logged in.

For example very similiar to the userid....

The element is what agency the user belongs to so I only want the user to see things in lists that pertains to their agency when it comes to drop downs in forms and lists as well.
 
I don't think you need a cookie.
I assume you have list (e.g. profile) linking the user to an agency?

What is your setup? Are all your lists containing an element storing the agency? or an element storing the userid?
 
Yes each registered user has an assigned agency but could have two agencies..... As well other lists have a agency element as well..... What I need to happen is that when someone is filling out a form this field is automatically completed or if they have two agencies they belong to they can select the appropriate agency.

I am having trouble with getting the agency element to autofill from what agency the person imputing the data belongs. The other issue is that some people may belong to two agencies.... In the end I will need to come up with verification process to ensure the user has chosen the correct agency. For example when they select their agency if they belong to more than one agency a pop up would show asking if they have chosen the correct agency.
 
What exactly do you mean by agencies? Are they a purely Fabrik implemented concept, i.e. an agency list, and a user list, with a join of some sort between them?

Or are "agencies" J! usergroups / viewing levels?

-- hugh
 
Here is my set up

Table 1 is Agency List (agencies) [has a left join to agency_users]

id
date_time
agencyname
director
phone

Table 2 Registered Users (registeredusers) [this is the juser joined table which creates new users]
id
date_time
agency [this is where the user's agency is selected.... What I want to happen is this for example.... John Doe School Administrator logs in to create a new student account... this drop down would show which schools he is the administrator of and allow him to select one of the schools.... If he would only belong to one agency then it would default that agency]
lastname
firstname
fullname
username
password
blcokfield
userid
usergroup
emailaddress
Table 3 Agency Users (agency_users) [many to many join] Each agency can have many users and each user could belong to more than 1 agency.
id
date_time
agencyid
userid
 
this is what I have done so far but it is not working...

on table registered users element agencies (databasejoin to agency_users)

Joins where and/or order by statement (SQL)
Code:
WHERE '{agency_users___userid}'= '{$my->id}'
 
In your list/form "registered users" you don't have a placeholder
{agency_users___userid}.
Try with
WHERE {thistable}.userid ='{$my->id}'
 
at least I assume that it is the concat label I need to use to display this...

In table agency_users agencyid logs the value of agencies primary key value.... But has a label of the agencies name...

When I use the dropdown from agency_users the lable shows the number not the name of the agency... I have tried this in the concat lable but it dont work.

{thistable}.agencyid_raw
 
Ok I got all the above problems solved this is what I used in the concat.

(SELECT agencyname FROM agencies WHERE id={thistable}.agencyid)

Now a problem I didn't think about was that when the user is created they will not be added to the agency_user table.... Any advise how to make the an automated process...? Is there a way to do this with the scheduler?
 
PHP:
$db =&JFactory::getDBO();
$db->setQuery("SELECT `agency` FROM `registered_users` where `userid` = '$My->ID'");
$field = $db->loadResult();

I tried this but I am not so sure I have the syntax right
 
Ok so I did some research on the insert statement and it appears I may of needed a insert select statement to accomplish what I am trying to do.... This is what I came up with but I believe their may be a syntax error... Because it's not working. This is my settings.

Published: Yes
do: php
in:both
on: new
process script: before the form data is loaded (onBeforeLoad)

PHP CODE
PHP:
$db =&JFactory::getDBO();
$db->setQuery("INSERT INTO 'testlist' ('field') 
SELECT  'agency'
       FROM   registered_users
WHERE userid = '$my->id'");
$field = $db->loadResult();
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top