First, you will need to create a new endpoint that can handle the request. It can receive a JSON string that it can parse to transform it into your internal representation. That internal representation you can save as you normally do. I am a Java dev, so using the JPA API it can be easily done.
Now, on the HTML page, you have to stop the form from being submitted. I know how to do this using jQuery.
Let's assume your form has the id "myAwesomeForm":
The magic happens in the submitForm() method. After that we just prevent the actual form submission in the normal way.
Now, submitting the form data. How you transform it into JSON is up to you, but here are libraries out there that do this based on the input field names. I used such a library here.
functionsubmitForm(form,onComplete){varjsonData=JSON.stringify(form.serializeJSON());varaction=form.attr("action");varmethod=form.attr("method");sendRequestWithData(action,jsonData,method,onComplete);}functionsendRequestWithData(url,jsonData,method,onComplete){$.ajax({url:url,dataType:'json',type:method,contentType:'application/json',data:jsonData,processData:false,success:function(data,textStatus,jQxhr){if(data.redirect){// data.redirect contains the string URL to redirect towindow.location.href=data.redirect;}if(onComplete===undefined){location.reload();}else{onComplete(jQxhr.responseText)}},error:function(jqXhr,textStatus,errorThrown){parseAndShowMessage(jqXhr.responseText);}});}
P.S. This is just a short example, and it may contain some errors, but you get the general idea.
First, you will need to create a new endpoint that can handle the request. It can receive a JSON string that it can parse to transform it into your internal representation. That internal representation you can save as you normally do. I am a Java dev, so using the JPA API it can be easily done.
Now, on the HTML page, you have to stop the form from being submitted. I know how to do this using jQuery.
Let's assume your form has the id "myAwesomeForm":
The magic happens in the submitForm() method. After that we just prevent the actual form submission in the normal way.
Now, submitting the form data. How you transform it into JSON is up to you, but here are libraries out there that do this based on the input field names. I used such a library here.
P.S. This is just a short example, and it may contain some errors, but you get the general idea.
Thank you, I'll try to use this.