HTML form submit to fieldname/fieldvalue table

Questions, tips and tricks and techniques for scripting in Servoy

HTML form submit to fieldname/fieldvalue table

Postby Westy » Wed May 27, 2015 5:29 pm

We want to allow our customers to do a html form submit from their website that will place the submitted data into a fieldname/fieldvalue table that can be accessed by our Servoy solution. The html submit form must be within their own html file (not a Servoy form).

What would a Servoy method look like that can receive the data, parse it, and place it into the fieldname/fieldvalue table? We will not know the field names, nor the number of fieldname/fieldvalue pairs to be submitted in advance.

Dean
Westy
 
Posts: 833
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: HTML form submit to fieldname/fieldvalue table

Postby ROCLASI » Wed May 27, 2015 9:04 pm

Hi Dean,

So the form is hosted on their own website?

You could use the Velocity plugin for this.

Your HTML form would be something like this:
Code: Select all
<form action="http://my.server.domain/myWebformProcessor/" method="post">
    <!-- all your fields and perhaps submit button -->
</form>

Your method would then look something like this:
Code: Select all
function vr_getContext(request) {
    if ( request.method === 'POST') { // sanity check
        // Get an array with all the parameter names (which corresponds with the field names in the web form)
        var _aParamKeys = Object.keys(request.parameters);
        for (var i = 0; i < _aParamKeys.length; i++) {
            foundset.newRecord();
            // I guess you want to add some identifying value here as well
   
            // store the key/value
            foundset.fieldName = _aParamKeys[i];
            foundset.fieldValue = request.parameters[_aParamKeys[i]];
        }
   
        // return a response (see Velocity Wiki)
    } else {
        // not a POST, handle accordingly. For example return a 403 (not allowed)
    }
}


Hope this helps
Robert Ivens
ROCLASI Software Solutions / JBS Group, Partner
SAN Developer / Servoy Valued Professional / Servoy Certified Developer
Twitter: @roclasi / @servoyforge
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5209
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: HTML form submit to fieldname/fieldvalue table

Postby Westy » Wed May 27, 2015 10:38 pm

Thank you very much.
Dean
Westy
 
Posts: 833
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA


Return to Methods

Who is online

Users browsing this forum: No registered users and 2 guests

cron