Page 1 of 1

PHP - set value of the field in the form.

Posted: Fri Jan 25, 2019 10:33 am
by Janusz
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?

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

Posted: Fri Jan 25, 2019 11:25 am
by kev1n
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.

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

Posted: Fri Jan 25, 2019 1:03 pm
by Janusz
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()

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

Posted: Fri Jan 25, 2019 1:48 pm
by Janusz
So finally I noticed nuID(); which I can use as a uniqe numer for events name - so it solved my issue.