Using a standard HTML form

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
jyoung
Posts: 653
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Using a standard HTML form

Post by jyoung » Sun Mar 20, 2016 11:14 am

I have a unique use case where I need to POST a html form to a third party, in this case a credit card processor. The form itself must be POSTed to the processor in order to reduce our PCI compliance, so I cannot that data (credit card numbers) up to a server module, then post to the processor.

I am trying to figure out how to do this with LANSA. I think I can use an HTML Container and dynamically generate the form that would handle the POST. I could use an external stylesheet resource to handle the styling.

Is there another way to do this, an external resource perhaps? A embedded web page may work but since it renders to an iframe I will have to look into how the processor redirection will work.

Just looking for ideas.

Thanks,
Joe

dannyoorburg
Posts: 157
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

Re: Using a standard HTML form

Post by dannyoorburg » Mon Mar 21, 2016 1:20 pm

Hi Joe,

I know you can dynamically create a form in JavaScript and submit it, I've got a bit of code that looks like this:

Code: Select all

  
  var
  	strUrl = "someURL.com",
  	postdata = {"key1": "Value1", "key2": "Value2"};
       
   // Create the form...
   var 
      form = document.createElement( "form" );

   form.setAttribute( "method", "post" );
   form.setAttribute( "action", strUrl )
   
   for ( var key in pPostData ) 
   {
      var 
         hiddenField = document.createElement( "input" );

      hiddenField.setAttribute( "type", "hidden" );
      hiddenField.setAttribute( "name", key );
      hiddenField.setAttribute( "value",  pPostData[ key ] );

      form.appendChild( hiddenField );
   }

   document.body.appendChild( form );
   form.submit();

and it would be pretty easy to encapsulate this in a (non-visual) Widget so you can write some RDMLX that provides the values and eventually calls submit...

But in the way I use it myself, the request comes back with HTML that then refreshes the whole page... I'm not sure if that's what you're after.

Also, you mention style-sheets, is there something visual to this that you wouldn't do in RDMLX?


Danny

jyoung
Posts: 653
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Using a standard HTML form

Post by jyoung » Mon Mar 21, 2016 11:58 pm

Hi Danny,

Its got to be visual as I have to collect the credit card data from the user then post it to the processor. I can create the form dynamically, via RDMLX or JavaScript. My current thought is to try JQuery for input validation, Handlebars for the form template and a sprinkling of CSS to make it look nice. Being somewhat new to LANSA I did not know if there was a better more "LANSA" like way to do this.

The response back will be a redirect to a success or error page. If I did not have the PCI issues, this would be an easy web page that collects the data and I would handle the post to the processor in a server module.

Its kinda odd, because one of the greate features of LANSA is that it remove this kinda stuff and here I am having to do it. :D

dannyoorburg
Posts: 157
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

Re: Using a standard HTML form

Post by dannyoorburg » Tue Mar 22, 2016 9:23 am

Hi Joe,

In the sample JavaScript I gave you, I create a form-element on the fly, it's not actually on the page somewhere.

I expect all user interface and validations to be done in RDMLX. Only when the user clicks a button I expect the event-routine's RDMLX to pass the user's credentials into some JavaScript (through a Widget) that then creates the form on the fly and submits it.

In general, if you need to get down to the JavaScript level for any reason, it's best to make a Widget in the Repository. They can be visual controls or just plain old objects if all you need is a bit of JavaScript functionality, like in this sample.

In this case we only need to descend down into JavaScript because the form-submit logic is not (yet) available in RDMLX.

If you can talk to this third party using AJAX you'd just stay in RDMLX and do it all through an instance of #PRIM_WEB.HttpRequest.

Have you got a link to the some documentation about this third party API? I'd like to understand how they expect people to use it.


Regards,
Danny

jyoung
Posts: 653
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Using a standard HTML form

Post by jyoung » Mon Apr 04, 2016 11:03 pm

I went round and round with this until finally settling on a solution similar to the one you suggested.

The .NET developer in me shied away from direct DOM manipulation, however in the long run that turned out the be the best way in this situation.

Thanks for the suggestions.

blaynec
Posts: 7
Joined: Wed Dec 09, 2015 3:55 am

Re: Using a standard HTML form

Post by blaynec » Sat Oct 08, 2016 2:53 am

Not sure whether to start a new topic or not - so just decided to reply to this message.

I'm trying to post a form in Lansa as well - using a VL Web app as well as a Client-Server PC app (VL Forms).
Is there functionality in Lansa or through Lansa Integrator to post an html form?

What I'm trying to do is interface with this service to send SMS messages:
https://www.plivo.com/docs/getting-star ... ingle-sms/

In .Net it is pretty simple to do this. What is the best way to do this in Lansa?
Also, it sounded like there may eventually be more support built in to Lansa to post an html form when you said: "the form-submit logic is not (yet) available in RDMLX".

Thanks

marco.kam
Posts: 7
Joined: Thu Apr 07, 2016 2:03 am

Re: Using a standard HTML form

Post by marco.kam » Mon Oct 10, 2016 1:20 am

Hello blaynec,

Since you have a requirement to send an SMS for both a VL Web as well as a VL Form App, an approach would be to do this from the server using Lansa Integrator, so that the function or reusable part can be reused in both applications. This function or reusable part would then be used in a server module (for VL Web) or a server function (for VL Form).


One way to do this in Integrator would be to use the HTTPService along with the OutboundNameValue handler:

http://docs.lansa.com/14/en/lansa093/in ... %7C_____11

(Sorry, the url doesn't work correctly with the forum url tool. Just copy and paste the entire string to your browser)


In your specific case, the Integrator code would look something like this:

SEND HANDLER(OutboundNameValue) HOST(api.plivo.com) URI(/v1/Account/{AUTH_ID}/Message/) USER({AUTH_ID}) PASSWORD({AUTH_TOKEN}) METHOD(POST) SECURE(*YES) SERVICE_LIST(PARAMS)

Make sure to replace {AUTH_ID} and {AUTH_TOKEN} with your specific plivo account values.

The PARAMS list should be defined as a list with 2 fields, one to hold the value of the name of the parameter you want to send and one to hold the value of the parameter you want to send. This is where the other information like 'src', 'dst', 'text' should be set. Make sure you populate your list before using the Integrator command to send.


The documentation you sent doesn't mention it explicitly, but I looked at the Node.js source code and the Auth_ID and Auth_Token are being used for basic authentication, which is why I've added that to the SEND command above.


Hope this works for you!


Marco

marco.kam
Posts: 7
Joined: Thu Apr 07, 2016 2:03 am

Re: Using a standard HTML form

Post by marco.kam » Mon Oct 10, 2016 1:30 am

Just a follow up on this.

From the Plivo documentation, it is unclear whether the service will accept name/value pairs. The Node.js code POSTs the data as json. You can do this in Integrator by using the HTTPOutboundJSONBindService instead. The SEND command would look very similar to the example I wrote, without the use of the PARAMS list. You'd have to use Integrator Studio to do some JSON definitions, and then also the other commands for the service like BIND and WRITE in order to send the specific JSON that you want.

Hope that makes sense.


Marco

blaynec
Posts: 7
Joined: Wed Dec 09, 2015 3:55 am

Re: Using a standard HTML form

Post by blaynec » Tue Oct 11, 2016 1:31 am

Marco,

I haven't used Integrator before, so I'll start the learning process on that.

That is good information and looks like exactly what I need.
Thanks for your reply!

GregSippel
Posts: 25
Joined: Thu May 19, 2016 11:34 am

Re: Using a standard HTML form

Post by GregSippel » Tue Oct 11, 2016 8:42 am

There is another method you might like to explore. You can create and send JSON based HTTP requests directly from a VL webpage. If you have a look at the samples in VL, you will find the weather app example. This shows a basic example of not only making the request but also handling JSON.

Cheers
Greg

Post Reply