concatenate 2 values as read-only default value for field

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
yvonnes
Posts: 5
Joined: 2015-04-06 17:44

concatenate 2 values as read-only default value for field

Post by yvonnes » 2015-04-06 18:52

Hello,

I would like to create a field with a read-only default value that appends / concatenates two values from the current record into one unique string. Is this possible with the 'default' setting in the Appgini field definition? If so, I haven't had any luck getting the syntax right so far :?

For example, perhaps the username (from the list of automatic values) appended to the record's primary key (which is an auto increment field) or ideally with a random number to get something like "username5982496".

Basically, this would create a second unique field that I could use instead of the record's primary key to access a specific record.

I need something like this because I have a page that outside of my Appgini application that generates a report accessible by URL using this table's primary key as selection criteria within the URL. However, since the primary key is an auto increment field, it's very easy to change that part of the URL and view a report intended for a different user.

If a different unique (but not simply auto incremented) field can be used instead of the primary key in the URL for that report, then it would be more difficult to guess the url for a different user's report - though not impossible, of course.

I want users to be able to easily and quickly view their own report without necessarily having to log in anywhere first. Although there is no personal information displayed in these reports that would lead to any privacy concerns, I still want to discourage users from looking at content not intended for them.

Thanks for any tips and advice :)

mariosantoso
Posts: 3
Joined: 2015-04-08 08:38

Re: concatenate 2 values as read-only default value for field

Post by mariosantoso » 2015-04-08 08:51

Hi,

You can try this, it's simple and tested it already.

My test table is like this...
id = primary key
name = var, required
nameid = var, unique, readonly

Put this line into the table hook init function
sql("UPDATE tablename SET nameid = CONCAT(name, id)", $eo);

There are other ways of doing it, this is just one of it. I hope this help.

yvonnes
Posts: 5
Joined: 2015-04-06 17:44

Re: concatenate 2 values as read-only default value for field

Post by yvonnes » 2015-04-12 16:30

That worked perfectly, thanks! :D

I also added a second line because one of the two fields I concatenated had the possibility of spaces being included, which would cause problems when using it in the URL to access the report. So, I added a line to strip out any spaces in the concatenated field, as follows:

sql("UPDATE tablename SET nameid = CONCAT(name, id)", $eo);
sql("UPDATE tablename SET nameid = replace(nameid, ' ', '')", $eo);

MI000001
Posts: 6
Joined: 2015-08-16 13:13

Re: concatenate 2 values as read-only default value for field

Post by MI000001 » 2015-08-25 16:25

Hello, is my form correct?

function Properties_init(&$options, $memberInfo, &$args){

sql("UPDATE Properties SET id2 = CONCAT(Reserved6, id)", $eo);

return TRUE;
}

thanks!

MI000001
Posts: 6
Joined: 2015-08-16 13:13

Re: concatenate 2 values as read-only default value for field

Post by MI000001 » 2015-08-30 23:46

Hi Yvonnes or Mario, i did this and it works but i have a problem (did you too have the same problem?) when editing records with this setup...

I think there is a bug…

I have field "IDprefix" a hidden and read only field with a default value of “BREP”

I create new records with they way using the joining of two fields into one (ie BREP010010), all is good.

I try to edit the existing record that was successfully created, (trying to add a street name let's say and save it) when I click save I get that error…

ERROR: IDPrefix you can not leave that field empty

the IDprefix is not empty, it has a default value or BREP and it is read only, when made visible in the detail view, the value is there (though it is read only so i can not edit it) but the default value is there nontheless...

Strange because the field is not empty, it has a predefined default value…

What do you think? did you have this problem and if yes, were you able to fix it and how please if you can share...

Thank you!!

User avatar
a.gneady
Site Admin
Posts: 1287
Joined: 2012-09-27 14:46
Contact:

Re: concatenate 2 values as read-only default value for field

Post by a.gneady » 2015-08-31 18:10

Since the field is read-only, and has a default value pre-filled to it, there is no need to set it as "Required" in AppGini. Unchecking this option would remove the error message.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

Post Reply