Forms: How to set value of form field, getting from custom table.

john martin asked on August 15, 2017 18:05

I would like to manage hidden form fields but i want to populate from custom table. Since I have different values for different scenarios. Can any one help me out for this. Thanks!

Correct Answer

Peter Mogilnitski answered on August 15, 2017 19:12

What form field do you mean? Then Kentico Document Form with document properties, online forms, or actual html form? Depends on your scenario I guess you can probably do it with macros, for example: {%GlobalObjects.CustomTables["customtable.tableName"].Items.Where("ItemID=123")("FieldName")#%}

2 votesVote for this answer Unmark Correct answer

Recent Answers


john martin answered on August 15, 2017 19:25

Peter M, I am using kentico online forms.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on August 15, 2017 19:32

You can put the macro above in your field General\default value.

1 votesVote for this answer Mark as a Correct answer

john martin answered on August 17, 2017 17:25

Hey Peter M, Thats great!! I have another question, I have a kentico form which is in iframe page(www.abc.com/child-page-iframe) which opens through a modal pop-up on a parent page(www.abc.com/parent-page-outside-iframe). I would like to get parent page url in form field. Can you please help me for this?

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on August 17, 2017 19:44 (last edited on August 17, 2017 19:56)

John, It would require a bit of a client scripting. I guess the easiest way would to wrap you text box into <div> tag with some id (for ex. mytexboxdiv) and some javascript that sets value to your text box:

if  (window.parent != null) {
    document.getElementById('mytexboxdiv').getElementsByTagName('input')[0].value = window.parent.window.location.href;
}

HTML Envelope Content before:

<div id="mytexboxdiv">

HTML Envelope Content after: Image Text

P.S. the editor does not let me paste script here

0 votesVote for this answer Mark as a Correct answer

john martin answered on August 28, 2017 16:12

I would like to get itemID from query string and get name of item from custom table like http://www.abc.com?itemid=123. how can i use below macro expression to get from querystring?

{%GlobalObjects.CustomTables["customtable.tableName"].Items.Where("ItemID=123")("itemName")#%}

I tried this way but not succeeded: {%GlobalObjects.CustomTables["customtable.tableName"].Items.Where("ItemID={?itemid?}")("itemName")#%}

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.