How can I access/read a field from the input form?

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
compusoft
Posts: 18
Joined: 2023-05-05 09:14

How can I access/read a field from the input form?

Post by compusoft » 2023-05-05 22:19

Hi

Is there a way that I can read or access a field that the user is typing, to incorporate its value in a search?
for example, this is my query for the lookup Sites

SELECT `Sites`.`id`, `Sites`.`Description` FROM `Sites` WHERE `Sites`.`id` NOT IN (SELECT `Reservation`.`SITIO` FROM `Reservation` WHERE `Reservation`.`DATE` = '2023-05-05')

It works fine, but only for the date '2023-05-05'. What I need is to replace this constant for the value than the user is introducing in Reservation.Date at the time of the capture

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: How can I access/read a field from the input form?

Post by pbottcher » 2023-05-06 07:47

Hi,

can you be a bit more specific on how you want this to happen. Shall it be at the time the user enters some data, or when the user saves a record?

In general you can access the entered data via the $_POST, $_GET or $_REQUEST arrays.
If you use the standard Appgini form for date input you will need to gather the 3 fields representing the day, month and year and put them together.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

compusoft
Posts: 18
Joined: 2023-05-05 09:14

Re: How can I access/read a field from the input form?

Post by compusoft » 2023-05-06 18:21

Hi pböttcher

Yes. It must be before the user saves the record
Screen1.jpg
Screen1.jpg (46.48 KiB) Viewed 2136 times
In this screeen, if the user change the value on field Reserva.Date (Fecha) the lookup query muste change to show only the sites that are not reserved on that date.

So, the field Reserva.Date it is conformed by 3 differente fields in AppGini? How they are named? And, how can I access their valies?

Thanks for your help!

compusoft
Posts: 18
Joined: 2023-05-05 09:14

Re: How can I access/read a field from the input form?

Post by compusoft » 2023-05-26 19:30

Update:

Using the following script I can now read the date selected by the user and store it in the Calculated variable

<scritp>
$j(function(){

$j('#Fecha-dd, #Fecha-mm, Fecha').change(function(){

var y = $j('#' + 'Fecha').val();
var m = $j('#' + 'Fecha-mm').val();
var d = $j('#' + 'Fecha-dd').val(); // Reading the data in DV

if (m < 10) {
m = '0' + m; // Formating
}

if (d < 10) {
d = '0' + d; // Formating
}
stfecha = y + '-' + m + '-' + d; // Now stfecha = 'YYYY-MM-DD'
$j('#Calculado').val(stfecha); // Puting stFecha in RESERVAS.CALCULADO (A field in the DV)
});
});
</script>

I made Calculado as a text field in the database, to be able to read it and use it in the next lookup advanced query

lookupQuery2.jpg
lookupQuery2.jpg (104.87 KiB) Viewed 1976 times
But it is not working. In fact, if I put an empty string instead of 'RESERVAS.CALCULADO' the efect is the same
What I'm doing wrong?

compusoft
Posts: 18
Joined: 2023-05-05 09:14

Re: How can I access/read a field from the input form?

Post by compusoft » 2023-05-26 19:37

Ups
In the previous screen, I use `RESERVAS`.`FECHA` = `'RESERVAS`.`CALCULADO`' (with double quote)
I tried also `RESERVAS`.`FECHA` = `RESERVAS`.`CALCULADO` (single quote) but the result is the same

Post Reply