Select specific option from dropdown list using PHP

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
ayussuf
Veteran Member
Posts: 39
Joined: 2021-01-20 17:15

Select specific option from dropdown list using PHP

Post by ayussuf » 2021-02-26 21:14

Hi,

Can someone here tell me how to select specific option from dropdown list using PHP?

Regards.
AppGini 5.92 - Upgraded to 5.94

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

Re: Select specific option from dropdown list using PHP

Post by pbottcher » 2021-02-26 21:56

Hi,

PHP is used on the server side. The dropdown is used on the client side. So what are you trying to do?
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.

ayussuf
Veteran Member
Posts: 39
Joined: 2021-01-20 17:15

Re: Select specific option from dropdown list using PHP

Post by ayussuf » 2021-02-26 23:38

Actually, I've heard from someone that javascript is not secure enough...

By the way... how about using jquery to do so?
AppGini 5.92 - Upgraded to 5.94

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Select specific option from dropdown list using PHP

Post by onoehring » 2021-02-27 08:25

Hi ayussuf,

if you want to make a pre-selection for the user JS is fine.
If you want to force the user to choose option X, you will need to add an additional check for example in the hooks/tablename -> before_update function. There you can change the dropdown using PHP to the value you want, ignoring any user's choice.

With JS probably pbötcher can help you when you post a list of item and tell us, which one should be selected.

Olaf

ayussuf
Veteran Member
Posts: 39
Joined: 2021-01-20 17:15

Re: Select specific option from dropdown list using PHP

Post by ayussuf » 2021-02-27 11:04

Thank you Olaf,

Is it possible using PHP in the hooks/tablename -> before_update function to pre select the specific option in dropdown list and user can change if he want to change? or at least can be displayed before the record being saved.

What I've done now was setting the $data[field] to specific record. But the problem is this selection was not displayed in the detail view before I save the record. It will only being displayed after the record have been saved first.

Actually I've tried doing this using jquery. But it just changing the value and text of the field. But the autofill field related to it didn't changed.
AppGini 5.92 - Upgraded to 5.94

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Select specific option from dropdown list using PHP

Post by onoehring » 2021-02-28 08:13

Hi,

the before_update is only run after the user clicks the save button. So this is the wrong place for something like this.
It's probably much easier to use jquery to select an option.
The other possibility (which I suppose is way more complicated) would be to manipulate the dropdown list before it is rendered in the browser. Probably in the _init function.
But well, you have the jquery to change the value, so why not use a different jquery to set the autofill to the value you want? Doesn't this work?

Olaf

Post Reply