What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    Submit form from php script

    Asked by goquote on May 26, 2017 at 03:36 AM

    Hello, I have a php script that submits data to a form. It uses JotForm's php library and the function createFormSubmission.

    Here is the submission part of the code:

    $msg=array("q1_yourName","John Smith","q2_yourAge","42");

    $jotformAPI->createFormSubmission($formID, $msg);

     

    The problem is that the key in this array (as I understand it) - "q1_yourName" is ignored and the second element - "John Smith" gets in the first field of the form no matter what I put in the first one. Same with the "q2_yourAge".

    I can make the array look like this: ("some_random_text","John Smith","more_random_text","42") and I get the same result.

    Can someone please explain to me how form submission with php works? I ques I am just doing something wrong.

  • Profile Image
    JotForm Developer

    Answered by Helen on May 26, 2017 at 04:40 AM

    Hello,

    Thank you for contacting us.

    You can submit data to your form using the JotForm API. Here is an example code:

      public function createFormSubmission($formID, $submission) {

            $sub = array();

            foreach ($submission as $key => $value) {

                if (strpos($key, '_')) {

                    $qid = substr($key, 0, strpos($key, '_'));

                    $type = substr($key, strpos($key, '_') + 1);

                    $sub["submission[{$qid}][{$type}]"] = $value;

                } else {

                    $sub["submission[{$key}]"] = $value;

                }

            }

            return $this->_executePostRequest("form/{$formID}/submissions", $sub);

        }

    I have checked your form but I could not find a form with username and age fields. However, I can say that the q1_yourName and q2_yourAge part must unique ID of the field. Please check this fields unique IDs. Here is an  example:

    Also, if you are using "Full Name" field, you must send to data like:

    q1_yourName[first]

    q1_yourName[last]

    Also, here is a JotForm PHP API page on Github, you can check it: https://github.com/jotform/jotform-api-php/blob/master/JotForm.php

    If you have questions about it, you can contact our API Team via this e-mail address: api@jotform.com

    Thanks,