Hi,

I am trying to create a booking request form using webform.

Currently, the user selects arrival and departure dates plus other details on the form. Once they click [Submit] I have a custom module which uses hook_webform_submission_presave to calculate the duration and cost of their stay. This value is then populated to a hidden field before a custom (webform) conformation email is sent including the cost.

Ideally, I would like to display this information before the submit button is clicked. Is there any facility to do this? e.g.
- A hook for a form event triggered by a change to a dropdown menu
- A hook for the [Next page] button

Any tips or suggestions would be much appreciated.

Thanks,
Fiachra

Comments

quicksketch’s picture

- A hook for a form event triggered by a change to a dropdown menu

Webform does not currently have this capacity. See #732114: Merge Webform Conditional into Webform (support for same-page conditional fields).

- A hook for the [Next page] button

You can always affect the Webform form through hook_form_alter(). I'd suggest just inserting the new information into the form as a #type = 'markup'. As noted in the Webform issue queue guidelines, support for custom code is not offered in the Webform queue, so actual implementation details you'll need to figure out yourself.

vernond’s picture

You could also use javascript to do the calculations and populate the "disabled" costs and duration textfields prior to Submit being pressed.

fiachra’s picture

Hi,

Thanks for the suggestions. hook_form_alter worked a treat. Select dates on first page of form and use hook_form_alter to populated fields on second page.

On quicksketch's suggestion I also changed the "cost" field as type "markup" and noticed something odd.

When using hook_form_alter to set the [#default_value] in a field of type markup, I noticed that the field is appearing on every page of the form. It also appears on the settings tab, the webform tab, etc...

Perhaps this should be in another ticket...

Best regards and thanks again,
Fiachra

quicksketch’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

drupup’s picture

@fiachra, Could you post how you did this? I'm trying to do something similar, but am hopelessly new at module development.