Which is the right way to call an external API when and Orbeon form is validated - orbeon

I have created an Orbeon form with 5 fields:
First name
Second name
e-mail
Phone
Case description
I want to call an external REST API (Nuxeo: Updating a Document) when the form is validated.
Reading Orbeon documentation I don't find the right way to do this.
Based on the documentation found in Orbeon Http Services it looks like it doesn't provide a way to customize the JSON that I must send in the API call with the form fields values.

Here is the general idea:
You can setup what button you want to have at the bottom of your form (doc).
Each button, run a "process". A process is composed of a sequence of actions (doc).
One possible action is send(), which allows you to send the XML containing the data entered by users ("form data") to a service you provide (doc).
With this, you can setup your form to have a "Send" button, which upon activation runs validation, saves the data, and sends it to your service.

Related

Is there a way to automatic load control values to Orbeon Forms?

We've just recently bought and started using Orbeon.
When the user edits a form, and want to save it, he press the save button, and we defined it to send the Orbeon-style XML with all the controls values to my C# REST API. When the user wants to continue editing the form, I call the Orbeon form, and there is a trigger, what fires when page loads, and it starts a REST API call to my C# REST API, to get the control values. Now we have to define map EVERY value. Eg. ControlSurname -> ControlSurname, ControlLastname -> ControlLastname ... etc.
Is there a way, that my C# API gives back the same Orbeon-style XML (maybe some values changed due to the business logic, but not the structure), and Orbeon parses it and put all the control values to its place? (Without mapping all the 87 control?) (It works in the save methon, you dont give a mapping when save...)
You can configure Orbeon Forms to load the initial data from a service. See the section Initial data from service for more on this.
The benefit of this approach is that you won't have to do any the mapping work you were referring to, and the drawback is that you have to make sure that the structure returned by your service corresponds to what the form expects, or your form might end up with missing fields or other problems.

One view having multiple button in asp.net mvc

I am not able to understand the flow on this page
how they are doing in MVC http://demo.nopcommerce.com/onepagecheckout
till now i created only one button for one page (view ) or provide me some similar link or similar code so i can understand
i want to implement same in my application
Thanks in Advance
The page is using AJAX to achieve the effect. Let's go through how it works.
The page is divided up into four sections.
Billing Address
Payment Method
Payment Information
Confirm Order
Each section is treated separately and are likely rendered using partial views. Each section has it's own form. When the user fills out a section and then submits that section, the form is submitted to a particular action. The Billing Address section submits its form to /checkout/OpcSaveBilling, the Payment Method section submits its form to /checkout/OpcSavePaymentMethod and so on.
When these forms are submitted (asynchronously, remember), the server handles the business logic and the validation and returns a result in the form of JSON. The JSON describes what happened, i.e. the result of the validation (success or fail), any errors that occurred and also contains HTML that the page can use to redisplay that particular section.
How is this data being remembered? Sessions. When forms are successful in their submission, the form data is stored per user in the session data. This way the system knows each user's settings and also knows where they are up to in the process.
The final step, Confirm Order, doesn't bother sending any form data because the server already knows everything through the session information.

Add Submit button on Orbeon Form Runner and then call custom Java REST API on submission

I am working on a POC (proof of concept) where I am evaluating Orbeon form builder/runner. I am using community edition, just in case, I will need to change the code, else the Professional Edition would do for POC.
I am integrating FormRunner with my web application running on different web server, which will call the FormRunner URL with some custom query parameters.
I want to remove the Summary, PDF and Review buttons from FormRunner and simply want the save button to function as submit button, so as clicking on it will submit the POST data to my custom Java code which will talk back to my web application, likely through REST API. The submit button then should redirect me to another page saying 'Your data has been submitted'.
I find it difficult to understand the area where I can change the code for expected behavior. Could you provide me some pointers in this regards please?
Thanks and Regards,
Mayuresh.
You shouldn't have to change the code for this, but instead use the oxf.fr.detail.buttons.*.* property to define which buttons are shown. Based on your description, you only need the workflow-send button, which, amongst other things can POST the form data to a service you specify.

Redirect to a remote URL with a POST verb and form data in MVC3

I currently have a small HTML form for a third party payment service, which comprises a flashy submit button and some hidden fields. These hidden field values are specific to the payment service, but the I wish to display the submit button as just one of many payment service options on a view based on a base class payment model, so I don't want to have specifics in my base payment model. Ideally I would like the submit button to call into an action in a service specific controller, and this action will gather service specific data, and submit a post request to the service's remote site, just as if I had clicked the submit button on the html form for that service. How can I achieve this?
If you want the form to be posted from the user's browser, you're going to have to use some client-side script either on a timer or on the Ready() event.
Can you do it server-side using HttpWebRequest?
i doubt that we can post data when redirecting. However what you want to achieve may be done using WebClient object from System.Net namespace. Not sure if it solves your problem but you can instantiate and call it like
WebClient client = new WebClient();
client.UploadString("http://www.xyz.com", "post", "a=b&c=d");

Ruby/RoR and many subprocesses

I am trying to build a free web application using ruby/rails It should be able to send sms through online forms of various mobile operators. (like this one (in russian)).
So, I need to
wait for the user, who wants to send an sms through my website.
establish connection to operator website. Probably, using Mechanize.
retrieve captcha
show captcha to the user
allow user to enter a message and captcha
submit form on operators website (with message, captcha, phone number)
The connection to the operator website should be alive during all this process (otherwise captcha will change). As far as I understand, I need to create a (sub)process each time sms is sent.
Could you please advise what is the best way of handling this in rails\ruby?
I am still rather new to web-development...
Should I use threads? forks? popen? using PTY? some external gem? How should I communicate with my process?
Assuming there's nothing special about the operator's web site, no, you don't need to keep a connection alive during the whole process. Generally speaking, forms on web pages work like this: You visit the URL, your web browser downloads the page with the form on it. In your case, it will also have an <img> tag or similar to show the CAPTCHA. Once your browser has downloaded the page, the connection is severed. After you fill out the form and click on Submit, your web browser opens a new connection to the server and sends the data, and the server sends its response (whatever page is shown after you click Submit).
All your program has to do is emulate this experience. So: 1) Download the page with the form on it. Scrape the form fields (make sure you don't miss any hidden fields--with a CAPTCHA there will probably be some) and the CAPTCHA. 2) Build a page to show your user that includes the CAPTCHA and a form with all the fields they need to fill out. If there were hidden fields in the original form, make sure you include their values (as hidden fields in your form) as well, because when the user submits your form you'll need them. 3) Then, when the user submits your form, send the data, including the hidden values and what the user entered for the CAPTCHA, to the operator. 4) Finally, check if the operator indicated success, and build a page to tell your user.
If you're doing this in Rails, you'll probably have two methods in your controller: One called e.g. 'show' (steps 1 and 2 above) that will scrape the CAPTCHA and other info from the operator's site and show the user your form view, and one called e.g. 'send' (step 3 and 4 above) that the form will submit to, and which will take their data and send it to the operator's web site, collect the response and tell your user if it was successful or not.
Note: You'll want to read the operators' terms of service before you bother with any of this. I'm fairly certain that this kind of thing will be against their TOSes and if they notice your server sending a lot of requests their way they're going to block you pretty quick.
To answer another question of yours, you can use DRb or background_job (aka BJ) to actually accomplish the sending in the background so that after your user submits the captcha they don't have to wait for the response. Or you could wrap this in ajax and have the DRb/BJ process notify you when the sms sending has happened so you can notify the user of success or any problems.
Typically opening threads in Ruby is something to avoid as there are so many great gems that do what we need. Not to say that you shouldn't use threads, just that for the most part it's probably already been done really well.

Resources