Buy Now
Sign in

FAQ search

How do I create an email subject using data from the form?

Details
Published: Thursday, 15 June 2017 12:52

This FAQ shows you how to combine form input data and text to make up an email subject. You can use exactly the same method to build, for example, a Reply To Name from first_name and last_name data from your form.

If you want to use just the data from a single form input then you can add the input name in the Subject box on the Email action Dynamic tab. Note: don't use curly brackets or quotes here.

If you want to include some other text as well as the form input, or you want to combine more than one form input then you need to create a new input entry in the $form->data array. Drag a Custom Code action into the On Submit event and move it before the Email action. Open the Custom Code action and add code like this:

<?php
$form->data['subject'] = "Some text {$form->data['input_name']} some more text";
?>

You can include more that one input name in the same way

After you have added the Custom Code action you can use subject in the Dynamic tab Subject box as above.


You could also use my custom Email [GH] action (available here for CFv4). This has merged the Static and Dynamic tabs together and will accept entries like this directly in the Subject box so that you don't need the extra custom action:

Some text {input_name} some more text

Note that with this action you must use curly brackets to identify where form input values should be used.