PHP - set value of the field in the form.

Questions related to customising nuBuilder Forte with Javascript or PHP.

PHP - set value of the field in the form.

Postby Janusz » Fri Jan 25, 2019 7:03 pm

Hi,
With PHP I want to assign a value to one field/object on Edit form.
Type: Input / text (ID: cyk_number)

I try to use PHP BS (to assign value of the next autoincrement index)

Code: Select all
$s = "SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'CTbaza' AND TABLE_NAME = 'Taski_cykliczne'";
$t = nuRunQuery($s);
$r = db_fetch_object($t);
nuSetFormValue('cyk_number', $r->AUTO_INCREMENT);


Since long time can not get it working.

trying as well simple commands like

Code: Select all
$r = "121";
nuSetFormValue('cyk_number', $r);


but as well can not change the field value.

Can you give some hints how to use PHP nuSetFormValue?
Janusz
 
Posts: 230
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: PHP - set value of the field in the form.

Postby kev1n » Fri Jan 25, 2019 7:55 pm

nuSetFormValue() updates an Object on an Edit Form After Browse after a Lookup value is chosen. It cannot be used in PHP BS.

But you can update your table in PHP AS (After Save) like this:

Code: Select all
// your other code here....

$s = "UPDATE yourtable SET cyk_number = ? WHERE yourprimarykeyx = '#RECORD_ID#' ";
nuRunQuery($s, [$r->AUTO_INCREMENT]);



BTW, there's an Input Type nuAutoNumber. Maybe you can use this one. It's probably easier.
kev1n
 
Posts: 276
Joined: Mon Oct 15, 2018 2:13 am

Re: PHP - set value of the field in the form.

Postby Janusz » Fri Jan 25, 2019 9:33 pm

Thanks for your feedback,

The nuAutoNumber looks interestig and would solve my topic.

What I noticed is that this numer is appearing in the field just after save.

The issue I have is - that based on some values in the fields I am generating mySql code with the nuBeforeSave() function.
and nuAutonumber is generated after that function.

Is it somehow possible that nuAutoNumber will be present in the field before nuBeforeSave().
Or the best if it would apprear during nuIsNewRecord()
Janusz
 
Posts: 230
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: PHP - set value of the field in the form.

Postby Janusz » Fri Jan 25, 2019 10:18 pm

So finally I noticed nuID(); which I can use as a uniqe numer for events name - so it solved my issue.
Janusz
 
Posts: 230
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland


Return to Custom Code