Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Problem saving Form with SubForm
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Problem saving Form with SubForm
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?
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Re: Problem saving Form with SubForm
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?
-
- 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
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?
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Re: Problem saving Form with SubForm
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?
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Re: Problem saving Form with SubForm
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...
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Re: Problem saving Form with SubForm
For the moment I solved with
So I get the ID immediatly and the subform records are saved regularly
Code: Select all
if(nuIsNewRecord()){
nuActionSave();
}
-
- 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
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.