4

I am trying to prefill a date field for an embedded Cognito form.

Below is shown the JavaScript code which I'm using in order to preload a form for the Controls Textbox, MultiLine Textbox, Radio Buttons, Date Field and Drop Downs. But the Date of Birth, which is a Date Field, does not populate with the prefill data.

Cognito.load("forms", { id: "1" , entry: {
                    "FormId": getParameterByName("encid"),
                    "Name": getParameterByName("name"),
                    "Address": getParameterByName("addr"),
                    "Date of Birth": getParameterByName("dateofbirth"),
                    "Sex": getParameterByName("sex"),
                    "Form Number": getParameterByName("formnumber"),
                } });

What is the syntax/format for prefilling dates in Cognito Forms?

3
  • 1
    Thx for a quick response karel. I can see that there are possibilities with JSON. But isn't there anything I can do without JSON. Coz I can able to achieve all the fields filled up with the relevant values apart from the date fields Commented Mar 31, 2015 at 6:50
  • Why couldn't you accomplish it? What failed? Commented Mar 31, 2015 at 7:00
  • Hi Vidar, 'Date Field' values were shown empty.. Any specific format to be followed for a Date Field? Commented Mar 31, 2015 at 7:05

1 Answer 1

3

Great question!

Dates are tricky things on the web due to a lack of an official standard for formatting. However, Cognito Forms uses the defacto standard, ISO 8601, as the format for dates in the JSON format. So in your example, the date would need to be something like "1962-03-29" in order to be processed. Also, when prefilling, the value can be a real JavaScript date, which is not supported in JSON, but is supported by prefill because it accepts a real JavaScript object.

However, this is likely not the cause of your issue. In order to ensure form field names are unique and well-formed in the JSON and code, the field label is used to create a field name that is used when writing calculations, converting to JSON, exporting to Excel, etc. So the name of your field in the JSON likely should be DateOfBirth instead of "Date of Birth".

In order to see the full structure of the form you are trying to prefill, we recommend using RequestBin to see what your form entries look like as JSON. Click on Create a RequestBin, copy the url, select Post JSON data to a website? under Submission Settings, paste the RequestBin url and save your form. Then fill out your form just like your end users would and refresh the RequestBin page to see the JSON.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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