Create form using API and Javascript

  • JD68
    Asked on March 24, 2020 at 10:22 AM

    I'm trying to create a form through the api using Javascript. In the documentation there is no example structure like the other languages provide.

    Javascript has this:

    JF.createForm(formObject,function(response){ /** successful response including created form object * */ document.write(response.title); });

    While PHP and others have this:

    $form = array( 'questions' => array( array( 'type' => 'control_head', 'text' => 'Form Title', 'order' => '1', 'name' => 'Header', ), array( 'type' => 'control_textbox', 'text' => 'Text Box Title', 'order' => '2', 'name' => 'TextBox', 'validation' => 'None', 'required' => 'No', 'readonly' => 'No', 'size' => '20', 'labelAlign' => 'Auto', 'hint' => '', ), ), 'properties' => array( 'title' => 'New Form', 'height' => '600', ), 'emails' => array( array( 'type' => 'notification', 'name' => 'notification', 'from' => 'default', 'to' => 'noreply@jotform.com', 'subject' => 'New Submission', 'html' => 'false' ), ), ); $response = $jotformAPI->createForm($form);

    Could you provide an example of creating a form with Javascript like the PHP example does?

    Thanks

    JD

  • Vick Support Team Lead
    Replied on March 24, 2020 at 10:58 AM

    Hey JD!

    Happy top help you today.

    If you are looking to use JotForm with API key then please follow this help guide below which includes step by step instructions.

    How to Create a JotForm API key

    Let us know if you have any further questions.

    Thanks.

  • JD68
    Replied on March 24, 2020 at 11:06 AM

    Thanks I know how to do that.

    If you look in the api documentation and select language to php, then go to post/form https://api.jotform.com/docs/#post-forms you see this:

    $form = array'questions' => arrayarray'type' => 'control_head''text' => 'Form Title''order' => '1''name' => 'Header', ), array'type' => 'control_textbox''text' => 'Text Box Title''order' => '2''name' => 'TextBox''validation' => 'None''required' => 'No''readonly' => 'No''size' => '20''labelAlign' => 'Auto''hint' => '', ), ), 'properties' => array'title' => 'New Form''height' => '600', ), 'emails' => arrayarray'type' => 'notification''name' => 'notification''from' => 'default''to' => 'noreply@jotform.com''subject' => 'New Submission''html' => 'false' ), ), ); $response = $jotformAPI->createForm($form);


    If you then look in the api documentation and select language to Javascript, then go to post/form https://api.jotform.com/docs/#post-forms you see this:

    JF.createForm(formObject,function(response){ /** successful response including created form object * */ document.write(response.title); });


    The Javascript example has no code in it. It doesn't tell me what the structure should be like the PHP example.

  • Ivaylo JotForm Support
    Replied on March 24, 2020 at 11:49 AM

    I would advise you to reach our API support: api@jotform.com since they will be more knowledgable about the topic. They will be able to provide further insctrutions and examples.

    Thank you.