How to make widgets talk to the JotForm

  • Profile Image
    bsiforms
    Asked on November 14, 2014 at 11:51 AM

    I've been reading this article: http://developers.jotform.com/widgets#customfields and trying to make a custom widget that is iFramed. The purpose of it is to have it load some values into hidden fields that come from php sessions and submit them into the form along with the contact information that I would have added through JotForm builder.

     

    As I'm iframing the widget from the appropriate domain, I am able to populate the input values from the session; however, I do not understand how to send it to the form that it belongs to and see the results in the submissions at jotform.com. My form has basic contact information fields like first name/last name and I want to capture a custom field that comes from the widget. The widget will be 0px by 0px, making it hidden.  

     

    In the documentation article it says:

    JFCustomWidget.sendData(data) You can use this method to send your field's results to JotForm at anytimedata object should include following attributes value Type: string This is your actual field result. It should be string (may be stringified JSON data)

     

    When it sends the results to JotForm, is it the form the widget belongs to? Or does it mean that it sends it to JotForm system...?

    Which question id does it send to? Am I supposed to declare a key/value pair on the data that i'm sending?

    Are there any more advanced examples for widgets other than what that article provides?

     

     

  • Profile Image
    KadeJM
    Answered on November 14, 2014 at 01:08 PM

    I think that you mainly are trying to get it to send into your jotform but it is not working as you are trying to send the data. Your widget should allow it to be sent and collected by your jotform with which it resides on as that is how it works to gather the information in the first place.

    Unfortunately, I have to agree with you that the part you mentioned can be a bit confusing so to do this you need to do is use a script similar to how our other widgets work.

    This particular example is set up to capture the data and send the values into your jotform which become apart of the submission. It also has a condition in it to display an error if it has a value that was left empty otherwise it will submit so that the associated data can be received.

    Example Code:

    JFCustomWidget.subscribe("submit", function(){

    var valid = true;

    var fieldValue = $('#fieldValue').val();

    valid = fieldValue .length > 0;

    var msg = {

    valid: valid,

    value: fieldValue

    }

    JFCustomWidget.sendSubmit(msg);

    });