Server Side Swift with Vapor · Creating Acronyms | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/870225-server-side-swift-with-vapor/lessons/24

After the user hits submit button, I want to show a thank you message along with the short form of the acronym (s)he has added along with the category under which it has been added to. How to achieve this? Any ideas?

@nikhilpandey you can create a new Leaf template with the success message you want and return that in the response to the successful POST request instead of returning the redirect. Hope that helps!

Hi Tim
Thanks for your response. Can you please give the sample code. So it will have an additional “POST” message. Also what if I make the output label in the form only but keep it hidden and show after the user presses submit button to show whether acronym creation has been success or failure.

It sounds like you want to use JavaScript instead of pure HTML? Because the book focuses on all HTML. So when you submit a form, that sends a POST request to the Vapor app, and you can return whatever you want (so it would be something like req.view().render("acronymCreate")).

Using Javascript to send asynchronous requests and make your site more dynamic (such as provided a success or failure message without a page reload) is out of scope of the tutorial, but you should be able to find plenty of articles online about making POST requests with Javascript and then manipulating your HTML

I want to use Vue.js as recommended by one of the founders of the Vapor, in his Berlin talk uploaded on YouTube on 10th Jan 2019.

That’s definitely out of scope of the tutorials! I suggest you start at the Getting Started page for Vue.js :smile: