Welcome to the nuBuilder Forums!

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

Problem saving Form with SubForm

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Problem saving Form with SubForm

Unread post by calida82 »

Hi I'm having a problem saving a form that has a subform. If the main form is a new record, the records inserted in the subform are not saved. if the main form is not a new record the subform records are saved. why does this happen? what am I doing wrong?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Problem saving Form with SubForm

Unread post by kev1n »

Please check this topic:

viewtopic.php?p=28989#p28989
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Problem saving Form with SubForm

Unread post by calida82 »

good morning, I checked that post, I had opened it but it's not the same problem. That case didn't save me because I didn't fill in all the fields of the record. here things are different. The new main form record is saved, what is not saved are the subform records. when you save what is the module or submodule saved first? perhaps the subform fields are not saved because the form, being a new record, does not yet have an id and therefore the foreign key of the subform records remains empty?
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Problem saving Form with SubForm

Unread post by kev1n »

Quoting my reply from the other topic:
With regards to the record not saving, are you using auto increment and is the primary key set in mysql. can you show the the table structure?
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Problem saving Form with SubForm

Unread post by calida82 »

sorry... yes I have a database with autoincrement primary key. is there a special way for this or before saving do I have to get the last record add one and fill in the field manually?
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Problem saving Form with SubForm

Unread post by calida82 »

I tried to make the id field of the main form visible and editable, I checked the last id in phpmyadmin and manually inserted the last number + 1 into the field as I intended to do with the code in beforeSave, then I filled in the main form and inserted some records in the subform then saved. the form is correctly saved with the id I entered manually, but the subform records are still not saved...
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Problem saving Form with SubForm

Unread post by kev1n »

Subforms do not work with auto increment pks.
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Problem saving Form with SubForm

Unread post by calida82 »

For the moment I solved with

Code: Select all

if(nuIsNewRecord()){
	nuActionSave();
}
So I get the ID immediatly and the subform records are saved regularly
nc07
Posts: 118
Joined: Tue Jun 04, 2019 4:05 am
Has thanked: 5 times
Been thanked: 22 times

Re: Problem saving Form with SubForm

Unread post by nc07 »

kev1n wrote: Thu Feb 08, 2024 7:44 am Subforms do not work with auto increment pks.
It only works if the parent form has been saved before subform data is filled.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Problem saving Form with SubForm

Unread post by kev1n »

I have also experienced the problem with subforms that use auto increment that sometimes random records in the subform are not saved. I haven't looked into this recently and I'm not even sure I could replicate that issue. This has led me to believe that subforms do not work well with auto increment keys.
Post Reply