I would like to enable html form submits directly to postgres on the same server that is running my Servoy solutions. Is installing php a good way to achieve this? If so, how can php be installed so it works with Servoy 6.0.x Tomcat?
Install PHP just for a simple input form into the database would be overkill. You could do it via a simple HTML and JavaScript page in the Servoy application_server/server/webapps/ROOT folder and then use jQuery to hit a RESTful webservice (or Velocity) that you create in Servoy.
Alternatively, you could also do a simple JSP page, as that is natively supported in Servoy.
I have the sample “restfulws_testpage.html” page working with the sample Servoy solution. However, I am struggling with the easy part.
The sample sends the contents of a single form field that contains firstName and lastName surrounded with XML tags. I am trying to do the same with a form that has multiple fields, each with data that is not surrounded with XML tags. I found the below code, which is similar to what I want:
However, I have not been able to modify the Servoy sample HTML page to work with multiple form fields with values that do not include XML tags. Attached is a page I created to help me understand the sample code and the servoy method required for a REST service POST (maybe it will help others like me who are new to XMLHttpRequests). How can I modify Servoy’s sample HTML page to work with multiple form fields with values that do not include XML tags?
I just quickly look at your code and I noticed you are sending things as XML. As far as I know the REST plugin only supports JSON. Do you require your data to be in XML format?
I tried the Servoy sample REST solution that comes with the default installation. The solution name is “servoy_sample_rest_ws”. A sample “restfulws_testpage.html” file is in the ROOT/examples folder. That is the file that has the XML. It works fine if the HTML form only has one field. However, my HTML forms will have multiple fields. I have not been able to modify the HTML code to allow posting of data for multiple fields. XML or JSON does not matter to me as long as I can post my data to a Servoy solution.
Seems that the web service plugin does support XML (and JSON/JSONP). I did a quick test with the demo solution in Servoy 6 using the following code that does accept more than 1 value:
HTML with AngularJS is very readable, and because you code the event(s) on the HTML tags all your code also keeps working when you change the structure of your HTML.
Something that is always a bit of a headache with libraries like JQuery where you have to code against the DOM structure using ID’s, classes or a path (and that path can change when you change the HTML structure).
As for curl, it’s one of the tools you can use to talk directly to web services. For instance there is also PostMan for Chrome and as Mac/Windows/Linux app. Or my favourite; Paw (Mac only). In fact that curl code was generated by Paw so I could show you a working syntax (without having to use Paw).