I’m sorry. I incorrectly assumed that the global $post object would be set and that get_the_title() would work as expected but that was not the case.
This makes it a little bit harder but still quite easy if you ask me. We need to add another function which adds the current page ID to the form args before it’s rendered:
function add_page_to_args( $args, $form ) {
$args['page_id'] = get_the_id();
return $args;
}
add_filter( 'af/form/args/key=form_596e935ba3e3b', 'add_page_to_args', 10, 2 );
And then we can adjust your email subject filter a bit:
`
function filter_email_subject( $subject, $email, $form, $fields ) {
$page_id = AF()->submission[‘args’][‘page_id’];
return get_the_title( $page_id );
}
add_filter( ‘af/form/email/subject/key=form_596e935ba3e3b’, ‘filter_email_subject’, 10, 4 );
`
Now instead of picking up the current page ID from the global $post object we instead get it from the form args which we set in the first filter. I tried this code in my local environment and it worked as expected. Try it out! ??