2

I'd like to pass a query parameter to the form so that it pre-fills at least one of the fields.

Is this possible when embedding on a website?

3

I am a developer for Cognito Forms.

You can pre-fill select fields on your form by modifying the embed code that you place on your website.

First off lets start with your normal embed code:

<div class="cognito">
<script src="https://services.cognitoforms.com/include/required"></script>
<script src="https://services.cognitoforms.com/session/script/iibc3e48-82t9-4642-b097-dp442bc9d123"></script>
<script>Cognito.load("forms", { id: "1" });</script>
</div>

We will be adding new code to the line that contains the script tag:

<script>Cognito.load("forms", { id: "1" });</script>

We will be pre-filling a name field, by targeting the field by label name, in this case "Name":

<script>Cognito.load("forms", { id: "1", entry: {Name: {First: "John", Last: "Smith" } });</script>

We are targeting the field "Name" and we are setting the value for "First" to John, and the value for "Last" to smith.

Once added your new embed code will look like this:

<div class="cognito">
    <script src="https://services.cognitoforms.com/include/required"></script>
    <script src="https://services.cognitoforms.com/session/script/iibc3e48-82t9-4642-b097-dp442bc9d123"></script>
    <script>Cognito.load("forms", { id: "1", entry: {Name: {First: "John", Last: "Smith" } });</script>
    </div>

The Name field is not the only field that can be pre-filled. You can use this method on any of our other fields, with the exception of the File Upload field.

  • Thanks for the fast reply Nicholas. When you say to target the field by label name, my label name is "Model Number", but there isn't a separate field like you have for First/Last Name. Would it just be: <script>Cognito.load("forms", { id: "1", entry: {Model Number: "text" } });</script> – coreyg Feb 3 '15 at 22:26
  • Everything in your script tag looks spot on, the only change you need to make to get this working is remove the space in "Model Number" The name of the field will need to have its spaces removed and each new word will need to be capitalized. You should have a script tag that looks like this: <script>Cognito.load("forms", { id: "1", entry: {ModelNumber: "text" } });</script> – Nicholas Gasque Feb 4 '15 at 12:33
  • Ok, that worked to pass plain text. For passing a variable through, I could just do the following, right: <script>Cognito.load("forms", { id: "1", entry: {ModelNumber: variablename } });</script> – coreyg Feb 4 '15 at 19:02
  • Could you be more specific in what you mean by a variable? If you would like to open a support ticket we can look at some more detailed examples. – Nicholas Gasque Feb 5 '15 at 15:00
  • Cool, I'll do a support ticket. Thanks for your help on this! – coreyg Feb 5 '15 at 18:20

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.