Two Forms Server Action Logic

How do I go about this I have a form that inserts a row into my database table named content then I need to pull the insert id from this row to be used in a follow up action that updates this row if needed and adds a row into another database tables named content_perms.

One idea I tried was a normal action and when its complete it runs a exec action in the library the param of the insert works great but the second forms values are not working am I going about this wrong?

I also messed around with flows but couldn’t seem to make this work?

You could try and maybe get a hint from this video. I think the principal is the same as what you want if I understand you correctly. The redirect page would be your second form instead of a details page.

Another way (I haven’t tried this) might be to use a global variable and set it to the new id in your server action. And. then on your second form, bind the value of a hidden field to the variable?

This is the logic I was sort of thinking but i forgot to add that my first form is different depending on what’s selected so there might be say 10 of these forms but then they all need to run the second form after passing the id, is there a way to set a variable of the front end from within a action I tried using set value but couldn’t get the variable back to the front or into the second form?

Have you seen this thread? Seems to be what you need possibly.

Thanks for the reply so the issue is one of two things

  1. when I grab the id from the first insert the id is fine but the second forms fields don’t get added into my action (assuming you can’t add 2 different forms in one action but also I tried added the second form to a exec form action the issue remains that my second form only gets the param id and won’t get the actual forms values)
  2. if I do it the other way just like a normal form all the fields in both forms work but the id is a issue this way as lets say I have 3 forms rows columns and perms I need rows or columns either could be run and Bothe forms are completely different to pass the insert id to the perms form which is always run

Maybe im misunderstanding the logic of how this would work?

So let’s start from the beginning - why are you using 2 forms?

The above image is my first set of forms depending on what value is selected depends on the form displayed only one is used at a time, these forms add a row into a database table.

Then this is the second form that needs to always run after one of the first forms runs, for this form to run I need the id of the insert passed into here so the update and insert have the id reference

So does that second form always shows after the insert runs? Do you automatically show it?

the second form is always shown on the roles tab

So how do you know which user is there and which data does he edit? Are the users logged in? Is the insert attached to some user id?
What’s your logic there?

Users are logged in and they select which content to display by clicking the images below

Each one will filter the first set of forms and show only the needed one the second one in roles applies to all the first forms and is always shown, any needed data to filter the first form set etc comes from these images been clicked

So as the user is logged in, on insert store the users id as well together with the insert.
Then in the other form you can run an update record server action and as you already have the user id related to the id inserted using the first form you can filter the data, get the inserted Id and update the record.

This seems to now be working great many thanks ill be trying the full action tomorrow but the values are now all together along with the form inputs so looks like this is all good to go now :smile: