1

I am embedding a Cognito form in my website. After the user submits the form, we save the form data to our database. The data will be further manipulated in our database.

When the user returns, our site generates a call to Cognito.load() which receives as an argument a jason-style argument that causes the embedded form to prepopulate the fields so that the user can review and modify the data.

The problem is that the Cogito.load() method generates a URL that is more than 2095 characters in length, which causes the load method to fail either because the browser is having a problem or the server doesn't like it. (Not sure which.)

To get around this, I tried to load the form differently. I just called the Cognito.load() method with the form ID, then, in a JQuery load method, populated the fields using JQuery after the form loads. That results in the form fields being prepopulated but Cognito's validation rules trigger errors on all required fields unless we click in and out of each required field. So that's not a good workaround.

Question: Is there another way in which we can embed the form on our site and have all the data prepopulated irrespective of the amount of data that have to be loaded?

Looking for behavior like the EDIT function from the Entries page of the Cognito web site. Our only twist on that is that data entered using Form-A will be prepopulated into Form-A for editing and review purposes but will also be prepopulated into Form-B ... Form-x for other purposes.

Thank you.

While waiting for a response, I tried this: I wrote a PHP script that loads the form using cURL and, in so doing, posts a JSON document with my form entries in it. Just to make sure I got the JSON right, I made a simple form with one text box field and posted the results to a pasteb.in. I copied the JSON from the pasteb.in and fed it back to Cognito's backend through cURL, hoping that would generate a form with the one field prepoulated. That failed. Here's my PHP script.

<?PHP
$json = '{"Form":{"Id":"3","InternalName":"Test","Name":"Test"},"Entry":{"LastPageViewed":null,"Number":"1","Order":null,"Origin":{"City":"Plano","CountryCode":"US","IpAddress":"108.206.122.80","Region":"Texas","Timezone":null,"UserAgent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36"},"PaymentToken":null,"Status":"Pending","Timestamp":"2015-05-31T00:33:10.049Z"},"Id":"3-1","MyText":"Hello"}';

$url = 'https://www.cognitoforms.com/JDReview1/Test';
//$url = 'http://requestb.in/1g6z8nr1';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: '.strlen($json)));
$result = curl_exec($ch);

echo $result;
?>

If I browse to the server that hosts this script, the result is a Cognito Form formatted exactly correctly BUT with a blank text box.

1

As of last night, you should be able to pre-fill data using the same methodology outlined in the post that you referenced above. The system has been updated so that large payloads on initialization result in a POST to load the form, rather than a GET.

Disclaimer: I'm an engineer on the Cognito Forms team..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.