Hey there! I’ve encountered this problem as well, but didn’t like how undynamic the solution was (required knowledge of the id, so it wouldn’t work with the advanced custom fields addon for contact form 7), below is a short example of the code I did to make this more dynamic (though I’m sure it can be more optimised, but I needed a quick fix for this).
$afterid = explode('id="wpcf7-f', $formshortcode);
$formid = explode('-',$afterid[1],2);
$form = str_replace(
'wpcf7-f'.$formid[0],
'wpcf7-f'.$formid[0].'-p'.get_the_id(),
$formshortcode
);
Where $formshortcode is either the shortcode of the form, OR, the output of the shortcode.