Project

General

Profile

Handling POST requests from forms

Added by Osman Zakir over 4 years ago

Hi, everyone.

I need to know how to handle POST requests from a form in Wt. I have a form generated by JavaScript that appears on an info window (in an external JavaScript file). I have a separate scripts.js file that I have a call to require() (for module-loading) in, and I use Browserify to load the dependencies and the module and put them into a single JS file called scripts-bundle.js, which is the file I'm using. I also have an index.html page in the apps doc-root. The script looks like this: https://gist.github.com/DragonOsman/c6e8fb15343544e662f474c5a526d1c2 and the HTML page looks like this: https://gist.github.com/DragonOsman/506bd2bae1dfe4c03a4bbe2a6d830324 . This is the CSS file if anyone's interested in it: https://gist.github.com/DragonOsman/3f3ba56ffd58476c6defaea95b066dc2 . This is my main.cpp: https://gist.github.com/DragonOsman/92bb7ebbc441047b6bacfe823e876f4d . If anyone wants to, they could use all of this code and compile and run the app on their end to see what's happening. Of course, right now there isn't much of a backend to speak of so clicking "Convert" on the form won't work. I need to write that. That's what I need help on and what I made this thread to ask about.

Anyway, I hope someone can help me. Basically I need help on how exactly to use WResource to handle a POST request coming from a form. And I also want to know what function to put that in. Also, do I need the convert() as part of the WApplication derived class, or should it be a regular function outside of any class? I do need my function that handles the request to call convert() either way, right?

Speaking of convert(), I need to ask: is the currency name or abbreviation inputted by the user going to have a different encoding, or would there be anything even aside from that that can make the currencies inside a vector of strings appear different enough to the computer for it to say that the string "USD" inputted by the user and the string "USD" from the vector aren't equal? I'm asking because I ran into a problem where it turned out that they weren't equal, back when I tried to create this same app using Boost.Beast.