• Hello,

    I am working on a multi-site website for my company that has some automatic functions happen when a theme is activated to help speed up my workflow. All templates/websites share the same contact form. Each time I create a new site and create a new form, I have to repeatedly update the Form and the Message body with the content I need. I currently have a function that changes the default Form content that works great. However, I cannot modify the default Message body for the life of me. All fields come back blank on my end. Here is my current code:

    function mod_contact7_form_content( $template, $prop ) {
      if ( 'form' == $prop ) {
        return implode( '', array(
            '[text* your-name placeholder "Name"]',
            '<div class="row mt-3 mb-3">',
            '<div class="col-12 col-md-6">',
            '[email* your-email placeholder "Email"]',
            '</div>',
            '<div class="col-12 col-md-6 mt-3 mt-lg-0">',
            '[tel* your-phone placeholder "Phone"]',
            '</div>',
            '</div>',
            '[select* options "Choose Option" "Service" "Maintenance" "Installation"]',
            '[textarea your-message x4 class:mt-3 placeholder "Explain Your Issue"]',
            '[submit class:btn-block class:btn-tempstar class:mt-3 "SEND YOUR MESSAGE"]',
        ) );
      } else {
        return $template;
      } 
    }
    add_filter('wpcf7_default_template', 'mod_contact7_form_content', 10, 2);
    
    function mod_contact7_form_body( $template, $prop ) {
      if ( 'mail' == $prop ) {
        $template = array(
            'body' => array (
            'Your contact information is as follows:',
            'Name: [your-name]',
            'Email: [your-email]',
            'Phone: [your-phone]',
            'Needed Request: [options]',
            'Message: [your-message]',
            'Be sure to follow up soon!',
          ) );
      } else {
        return $template;
      } 
    }
    add_filter('wpcf7_default_template', 'mod_contact7_form_body', 10, 2);

    Can you help with this?

    Thanks

Viewing 1 replies (of 1 total)
  • Hi,
    You return nothing for the condition:

    if ( 'mail' == $prop ) {

    At least you change the assignment lines:

    $template = array(

    on:

    return array(
Viewing 1 replies (of 1 total)
  • The topic ‘Changing default Message body with function’ is closed to new replies.