Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #987621

    Dear members and dear support,

    how i get in the contact form subject auotmatic the post title?
    Every post have a contact form below. And when a customer write me, than should automatic the post title as the subject.
    Its this please possible? I think i must create a function in the function.php. But i dont know how…

    Thanks for your help.

    regards stp

    #988041

    Hey strumpumpel,

    You can use this code – just add it to the child theme functions.php file:

    
    add_filter('avf_form_subject','avia_change_mail_subject', 10, 3);
    function avia_change_mail_subject($subject, $new_post, $form_params)
    {
        if( is_single() )
        {
        	$subject = urldecode(get_the_title());
        }
        return $subject;
    }
    

    If you want to add some static text before the post title use this code:

    
    add_filter('avf_form_subject','avia_change_mail_subject', 10, 3);
    function avia_change_mail_subject($subject, $new_post, $form_params)
    {
        if( is_single() )
        {
        	$subject = 'A new message on:' . urldecode(get_the_title());
        }
        return $subject;
    }
    

    and replace “A new message on:” with some custom text.

    Best regards,
    Dude

    #988162

    Dear dude,

    great thanks for you answer! I edit this code in the function.php from my child theme. But not happend in my subject on this contact formular…

    what for a typ must the subject field?
    Formular type element:
    text input or selection field or text area or checkbox or date picker or own html?
    I think date picker, checkbox and own html is not right.
    I try them out the other elements, but dont happend when i open the post with contact fomular. The subject is empty….
    What’s wrong?

    Thanks, thanks for your help!

    #989185

    Hi,

    Thanks for the update.

    I adjusted the filter a bit. Please try it again.

    add_filter('avf_form_subject','avia_change_mail_subject', 10, 3);
    function avia_change_mail_subject($subject, $new_post, $form_params)
    {
        if( is_single() )
        {
        	$subject = 'A new message on:' . urldecode(get_the_title(get_the_ID()));
        }
        return $subject;
    }

    Best regards,
    Ismael

    #989249

    Guys??? You are the biggest! :)
    The code worked perfectly now! Big thank you! :)

    Question: What is the 10 and 3 in “add_filter(‘avf_form_subject’,’avia_change_mail_subject’, 10, 3);”

    Biggest thanks and by by :)

    #989328

    Hi,

    Hahaha that is more advanced coding nuances. Priority is 10, accepted arguments is 3.

    Best regards,
    Jordan Shannon

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.