Imagine being paid to improve your favorite CMS!

It could be you! Umbraco HQ are hiring and are looking for both talents and senior developers. Wonderful workplace, friendly colleagues and competitive salary.

14 votes

Cultiv RestContour

Sometimes you want to just use Contour from, for example, a Flash movie or through an AJAX call. This is not currently possible with Contour out of the box, but this package will let you do just that! 

With this package you can do a GET or POST request to get all Contour forms, get the fields (including prevalues) of a specific form and fill a Contour form and send it without even being in an Umbraco context. It will give you any validation and manditory field errors in a json string for you to use as you see fit. 

After you install the package, make sure to add these few lines to the /config/restExtensions.config file (I hope to be able to automate this in a future release): 

  <ext assembly="/bin/Cultiv.RestContour" type="Cultiv.RestContour.SubmitContourForm" alias="submitContourForm">
    <permission method="CreateRecord" allowAll="true" returnXml="false" />
  </ext>

  <ext assembly="/bin/Cultiv.RestContour" type="Cultiv.RestContour.GetContourForm" alias="getContourForm">
    <permission method="GetAllForms" allowAll="true" returnXml="false" />
    <permission method="GetFormFields" allowAll="true" returnXml="false" />
  </ext>

Careful here: everybody has permission to post to the form.

Note: Remove the /bin/ reference when working with Umbraco >= 4.5

To get forms and fields:
Go to yoursite.ext/base/getContourForm/GetAllForms to get all of the forms available.

Then go to yoursite.ext/base/getContourForm/GetFormFields/?formGuid=xxx-xx etc to get all of the fields, and their paremeters and prevalues.

Submitting a form:
Go to yoursite.ext/base/submitContourForm/CreateRecord.aspx/ 
After the URL you are going to have to specify the queryString parameter "formGuid". This is the guid of the Contour form.

 

There are three more (optional) queryString paramaters that you can pass:

- nodeId - will indicate to which Umbraco node the form pertains (will be -1 when left empty)
- userIpAddress - the IP address of the user submitting the form (will revert to the server variable REMOTE_ADDR if left empty, please make sure that you don't get the server's IP address instead of the user's when using in a Flash or AJAX environment!).
- culture - example: value "en-US"; this is to force the form being submitted in a particular language, you need to use this if you are running a multilingual site and want to use dictionary items to send e-mails for example.

After that you can just use the querystring variables to send values to the form (&Name=My Name, etc.). These variables will be mapped one-on-one to the form field captions in Contour. 

 

Of course this also works with a POST as opposed to a GET.

All of these url's have an optional parameter:
- returnJSstring - if set to 1, the returned JSON string will be formatted for use in javascript immediately (javascript needs a little more escape characters).

Updates
1.0.1 - Workflow was triggered for each field, this is now fixed.
1.0.2 - userIPAddress and nodeId no longer mandatory, nice error message when formGuid is omitted.
1.0.3 - Errormessages configured in Contour (validation & mandatory on fields/forms) are now added to the JSON result - With full support for dictionary items. Also, the JSON string is now valid and there's an option to output JSON that will work immediately in JavaScript.
2.0.0 - Extra services to also fetch all forms and formfields
2.0.1 - Added support for multilingual sites through the culture parameter

Future plans:

  • Update the restExtensions.config file automatically during install;
  • Refactor and use JSON.net;

Screenshots

Project owner

Sebastiaan Janssen

Sebastiaan Janssen

Sebastiaan has 12338 karma points

Project Compatibility

This project is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
7.7.x (untested)
7.6.x (untested)
7.5.x (untested)
7.4.x (untested)
7.3.x (untested)
7.2.x (untested)
7.1.x (untested)
7.0.x (untested)
6.1.x (untested)
6.0.x (untested)

You must login before you can report on package compatibility.

Project Information

  • Project owner: Sebastiaan Janssen
  • Contributors: Nik Wahlberg
  • Created: 11/08/2010
  • Current version 2.0.1
  • License MIT
  • Downloads: 6958