Welcome to the nuBuilder Forums!

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

PHP - set value of the field in the form.

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

PHP - set value of the field in the form.

Unread post 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?
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

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

Unread post 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.
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

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

Unread post 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()
If you like nuBuilder, please leave a review on SourceForge
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

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

Unread post by Janusz »

So finally I noticed nuID(); which I can use as a uniqe numer for events name - so it solved my issue.
If you like nuBuilder, please leave a review on SourceForge
Post Reply