Page 1 of 2
PHP after browse in select object
Posted: Fri Jul 14, 2023 1:05 pm
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
Re: PHP after browse in select object
Posted: Fri Jul 14, 2023 1:10 pm
by kev1n
Re: PHP after browse in select object
Posted: Fri Jul 14, 2023 4:04 pm
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
Re: PHP after browse in select object
Posted: Fri Jul 14, 2023 4:22 pm
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.
Re: PHP after browse in select object
Posted: Fri Jul 14, 2023 7:04 pm
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
Re: PHP after browse in select object
Posted: Sat Jul 15, 2023 2:42 am
by kev1n
Code: Select all
nuJavaScriptCallBack("nuSetValue('det_montant', $r->typ_montant);");
Re: PHP after browse in select object
Posted: Sat Jul 15, 2023 7:31 am
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
Re: PHP after browse in select object
Posted: Sat Jul 15, 2023 8:13 am
by kev1n
Use nuDebug()
Re: PHP after browse in select object
Posted: Sat Jul 15, 2023 9:42 am
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 ?
Re: PHP after browse in select object
Posted: Sat Jul 15, 2023 12:45 pm
by kev1n
Is DET_TYPE_ID an object ID or is it set with nuSetPropety()?
It is case sensitive.