I've made this form where the user can insert some information, and I want to send this to a local Mysql server I have running. It likely involves some javascript but i'm just not exactly sure what. The server is also connected via a REST JPA backend with some endpoints, where I have an endpoint for creating a new entity. Just not exactly sure how to utilize it in the frontend, if that is even what i'm supposed to do.
Here is my form:
<form action="http://localhost:8080/api/products/addProduct" method="POST">
<table class="formTable">
<tr>
<td><label for=pName">Product name:</label></td>
<td><input type="text" id="pName" name="name" required></td>
</tr>
<tr>
<td><label for="pPrice">Product price:</label></td>
<td><input type="number" id="pPrice" name="price" required></td>
</tr>
<tr>
<td><label for="pWeight">Product weight (gram):</label></td>
<td><input type="number" id="pWeight" name="weight" required></td>
</tr>
</table>
<input type="submit">
</form>
I put the form-action as my REST endpoint but i've got no clue if that's correct or not.
1条答案
按热度按时间r3i60tvu1#
Yeah it's correct, yourfront_end is OK, at the backend you need to read the data through the endpoint on the action attribute on the form. Depending on which server side language you're using, for Express and Node.js the posted data can be found in the
And on Django,
And after getting the data, you'll probably validate it against your business rules Before storing it on DB. Note that you'll need mysql drivers for that particular serverside language which can be found on the docs of the server side framework that's youre using...
I hope this answers your question...