Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

PHP after browse in select object Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

PHP after browse in select object

Unread post by yvesf »

Hello,

In certain situation, it is better to use a select object instead of lookup object because you don't want to have the select list modified by the end user.
In that case, using the select object is better.

In lookup object, it is quite easy to prepopulate the current form with php code. see below :
Capture.PNG
Is it possible to do the same thing with a select field ? We probably have to create a procedure for that ? how can it be created ? Which event is used to call the php script ?
Capture1.PNG
Many thanks for your help,

Yves
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP after browse in select object

Unread post by kev1n »

Use nuRunPHPHidden() to run PHP code:

https://wiki.nubuilder.cloud/index.php? ... nPHPHidden
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: PHP after browse in select object

Unread post by yvesf »

Hello Kev1n,

Thanks for your answer.
I have created a proccedure I request like this below :
Capture3.PNG
and the procedure is :
Capture4.PNG
Unfortunately, it doesn't work. Do I made smthg wrong ?
Many thanks,

Yves
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP after browse in select object

Unread post by kev1n »

nuSetFormValue() can only be used in After Browse. Use nuJavaScriptCallback()

https://wiki.nubuilder.cloud/index.php? ... ptCallback

and nuSetValue() to set a field's value.
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: PHP after browse in select object

Unread post by yvesf »

Kev1n,

Callback is something difficult to apprehend for me.

Code: Select all

nuSetValue('det_montant', $r->typ_montant) 
should be probably on custom code of det_type_id behind onchange() event.
But I don't see how to use nuJavaScriptCallback() and how to "send" $r to the javascript side.
Maybe like this ?
Capture5.PNG
Thx for your help,

Yves
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP after browse in select object

Unread post by kev1n »

Code: Select all

nuJavaScriptCallBack("nuSetValue('det_montant', $r->typ_montant);");
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: PHP after browse in select object

Unread post by yvesf »

Code: Select all

$s  = "SELECT type.typ_montant FROM type where type.typ_code = ?";
$t  = nuRunQuery($s, array('#DET_TYPE_ID#'));



if (db_num_rows($t) == 1) {
   $r  = db_fetch_object($t);
$js="nuMessage('test');";
//$js="nuSetValue('det_montant',$r->typ_montant);";
    nuJavaScriptCallback($js);
   
}

it seems that my $t variable returns nothing. How can I see the content of my variable $t in php ? var_dump ?
det_type_id is a select object in the interface. Do I have to pass #DET_TYPE_ID# in the nuRunPHPHidden as a second parameter ?
Many thanks,

Yves
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP after browse in select object

Unread post by kev1n »

Use nuDebug()
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: PHP after browse in select object

Unread post by yvesf »

Code: Select all

$s  = "SELECT type.typ_montant FROM type where type.typ_code = ?";
$t  = nuRunQuery($s, array('#DET_TYPE_ID#'));
$n = array('#DET_TYPE_ID#');
nuDebug($n);


if (db_num_rows($t) == 1) {
   $r  = db_fetch_object($t);
$js="nuMessage('test');";
//$js="nuSetValue('det_montant',$r->typ_montant);";
    nuJavaScriptCallback($js);
   
}
By looking in the debugger, I have :

Code: Select all

[0] : Array
(
    [0] => #DET_TYPE_ID#
)
It seems that the content of the ui select object det_type_id hasn't been passed to the procedure. How can I do that ?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: PHP after browse in select object

Unread post by kev1n »

Is DET_TYPE_ID an object ID or is it set with nuSetPropety()?
It is case sensitive.
Post Reply