How to differentiate form posts from two different...
# help-with-umbraco
o
I have two mvc forms (contact form and call form) in an Umbraaco 13 web site. When used in seperate pages they work well. But if i place them in a single page and submit one form the other form also returns the values if form fails validation (e.g. an unchecked consent checkbox). When the form is submitted successfully both forms return their confirmation message. Any advices? Thanks in advance. https://cdn.discordapp.com/attachments/1221855614117089410/1221855614561423370/Screen_Shot_2024-03-25_at_18.52.13.png?ex=661418b7&is=6601a3b7&hm=51ccb7b8577b21361e5e0301347759489420d14fa3e14a7f293911c0ba07728d& https://cdn.discordapp.com/attachments/1221855614117089410/1221855614939168888/Screen_Shot_2024-03-25_at_18.57.36.png?ex=661418b7&is=6601a3b7&hm=6fc58cc13fb2c7f9d7423edbdf5ff6afe369d15932b8de8325dbf80ea1a088d7&
m
That sounds strange and should not happen by default. Do you have a form tag surrounding those forms?
o
Yes there's form tag. I'm sharing the html code generated and also model, view, controller screen shots. Do i miss something? https://cdn.discordapp.com/attachments/1221855614117089410/1222169369275269230/Screen_Shot_2024-03-26_at_16.02.18.png?ex=66153cec&is=6602c7ec&hm=e3e8d80245d4296263578788208ee12fa240729c3cd9f9cb549c16e194c663aa& https://cdn.discordapp.com/attachments/1221855614117089410/1222169369677795440/Screen_Shot_2024-03-26_at_15.55.16.png?ex=66153cec&is=6602c7ec&hm=eddd6ad23338f77d644100dd406d732efc74f015d482c57c8fae6a3dc28c7095& https://cdn.discordapp.com/attachments/1221855614117089410/1222169370210340864/Screen_Shot_2024-03-26_at_15.55.31.png?ex=66153cec&is=6602c7ec&hm=3094eea29e8f985fa20620b283e204ea0a029c1e5c48067af69c18b1c9f7232a& https://cdn.discordapp.com/attachments/1221855614117089410/1222169370801868830/Screen_Shot_2024-03-26_at_15.56.48.png?ex=66153cec&is=6602c7ec&hm=a58afdf88bfd5bbdfb7ba1dd60ac9742b40db750eef67940b20e9ebe4ea63a15& https://cdn.discordapp.com/attachments/1221855614117089410/1222169371783204915/Screen_Shot_2024-03-26_at_15.57.31.png?ex=66153ced&is=6602c7ed&hm=0f78bbd7914cfa11acc8b66b5e8515610a1585a3049bb68b1992f188aafa7fae& https://cdn.discordapp.com/attachments/1221855614117089410/1222169372500688958/Screen_Shot_2024-03-26_at_15.58.14.png?ex=66153ced&is=6602c7ed&hm=a800737de5118300b7e116b0081c5728dc847695570ab26537714234c64c5d59& https://cdn.discordapp.com/attachments/1221855614117089410/1222169373175844885/Screen_Shot_2024-03-26_at_15.58.46.png?ex=66153ced&is=6602c7ed&hm=09a5dfd91a36609376c72018d1c9d5b33417935962738e217db0ba843adee765&
m
But is there a form tag surrounding those forms? As in; do you have forms within eachother? How is the submit going? Is it just a post, or are you doing it client side with javascript?
o
No the forms have seperate form tags. Using @using (Html.BeginUmbracoForm(nameof(ContactFormController.Submit))) { .... } adds ...... I don't think i make a clientside post.
m
Just checked your views, I assume that in both views your checking for TempData["success"]? If so, than that's your issue.
As both views than check the same value in the tempdata, they both do stuff depending on that.
You could just use a different key for each form in your TempData, so it's unique for that form
For ex, TempData["Form1_Succes"]
o
Let me try.
Using different keys for TempData solved half of problem. The other half is; Only the first form (that appears first on html) works. The latter does not work. I tested switching locations of forms. Latter one doesn't work.
I tried to use unique variable names as email1, email2. Didn't help either.
m
What isn't working?
o
Solved: The problem was both forms have form fields and recaptcha hidden input fields with the same id. Updating all the input elements with unique id's solved the problem. Thank you.