Chapter 16 - Create Acronym - POST form

Good Morning,

I’m following the chapter 16, with personal changes to the Acronym’s model, and I’m having a issue. I made the form as in the book, but I need to pass two arrays in it. I don’t know why, but it doesn’t work. In the form, customers can choose through buttons different tax statements, and for each button pressed, my JS function pushes a value to the array. Every time the array is modify, the function retrieve the hidden input id and assign the array to it. Why the POST doesn’t recognize the arrays? I already checked the “input’s name” and they’re seems correct. When I click the send Button, the Acronym is created, the browser redirects to the acronym’s page but there is no array’s values, and an error occurs in the xcode’s console " [ ERROR ] Abort.404: Not Found (ApplicationResponder.swift:50). If I go to the browser console it log "Failed to load resource: the server responded with a status of 404 (Not Found) - http://localhost:8080/favicon.ico.

image 1
Image 2

Thank you very much for your help-

The 404 is a read herring, it’s trying to find a favicon so you can just ignore that. I would breakpoint in your create handle in Vapor and see what’s it’s populating your arrays with and then work backwards from there. You can look in the browser inspector too to see what the data being sent is.

(As a side note, you may have issues since there’s no standard way of doing arrays with with form data. For example, this StackOverflow post mentions two ways (and I think the second answer works with Vapor)

@0xtim Thank you very much Tim, I use your advice and finally I found a solution.
I post the data as a string, and in my WebsiteController, before the save.on(req.), y use the array.components(separateBy: “,”) to create the array and pass it.
I love the Vapor-Swift’s relation.
Keep working on it, it’s a powerful Web Framework!

1 Like