• Resolved gcarnegie

    (@gcarnegie)


    How should I combine multiple dynamic (or literal) fields in a single CF7 field?

    eg, I am populating a dynamic_textarea with the post_date,

    [dynamic_textarea your-message “CF7_get_current_var key=’post_date'”]

    but:

    1. The Post_Date needs reformtting from “2024-06-15 21:06:00” to UK date “15/06/24”.
    2. I also want to add some standard text before the date, within the same dynamic_textarea: – “I am interested in working with you regarding [TITLE], on [reformat(POST_DATE)]”

    Any help would be appreciated.

    • This topic was modified 8 months, 2 weeks ago by gcarnegie.
    • This topic was modified 8 months, 2 weeks ago by gcarnegie.
Viewing 1 replies (of 1 total)
  • Plugin Author Tessa (they/them), AuRise Creative

    (@tessawatkinsllc)

    So you’ll want to use a custom shortcode for this, something like:

    function gcarnegie_textarea()
    {
        // Call the CF7_get_current_var function directly, returns date formatted as YYYY-MM-DD HH:mm:ss
        $date = wpcf7dtx_get_current_var(array('key' => 'post_date'));
        if ($date) {
            // Convert string to DateTime object in UK date (GMT)
            $date = date_create_from_format('Y-m-d H:i:s', $date, new DateTimeZone('GMT'));
            if ($date !== false) {
                // Get the current title
                $title = wpcf7dtx_get_current_var(array('key' => 'post_title'));
                // Return with desired format and additional text
                return sprintf(
                    'I am interested in working with you regarding %s on %s',
                    $title,
                    $date->format('j/n/y')
                );
            }
        }
        return ''; // Return empty string on failure
    }
    add_shortcode('gcarnegie_textarea', 'gcarnegie_textarea');

    And then in your form tag, you can simply use this:

    [dynamic_textarea your-message "gcarnegie_textarea"]
Viewing 1 replies (of 1 total)
  • The topic ‘Multiple Parameters in a single CF7 field’ is closed to new replies.