Search code examples
webformskentico

Kentico 9: Customizing the Form action based on the page the form is on


I have a form that I want to include on each of 250 pages based on the same pageType. Thus I want to include the form reference in the template and have it render on all pages. this much seems to be working. However, I want to have the form to trigger an email send to a different email address based on the pages contactEmail property (entered as a property of the page/ defined on the pageType)

I am guessing I will have to build a custom form control or alternative form, but I don't know where to start and I have been pouring over the documentation for days. I tried enabling email notification and setting {% CurrentDocument.ContactEmail #%} as the recipient email, but that does not seem to work.

I am not sure what context I can use macros in the form building or if there is a way to reference the current document field values within the form.


Solution

  • CurrentDocument is not available when sending an email, but it is when saving a form. As a workaround I'd suggest you adding a new field to your form e.g. ContactEmail and setting {% CurrentDocument.ContactEmail #%} as a default value for it. Now you need to make sure fields is on the page, but hidden with CSS - use a custom layout or an alternative form.

    Now when saving form data, the system will save CurrentDocument.ContactEmail value along with form.

    The last step would be updating To field under Email Notification tab of the form with following macro {% ContactEmail %}.