Filling doc with the data entered in a form

[ad_1]

Hello,

Thanks for the feedback!

Yes you can achieve that. You’ll have to use PHP PDF library in order to generate a PDF. Here are the most popular PHP PDF libraries:

You don’t even need to set an Action in the Form UI if that’s the only thing your form is doing. You can use the global hook for that acfe/form/submit (See documentation).

Usage example:

add_action('acfe/form/submit/form=my-form', 'my_form_submit', 10, 2);
function my_form_submit($form, $post_id){
    
    // get fields input values
    $my_field_1 = get_field('my_field_1');
    $my_field_2 = get_field('my_field_2');
    $my_field_3 = get_field('my_field_3');
    
    // generate pdf file using library
    // save the file in /wp-content/uploads/
    // ...
    
}

Regarding the way to display the pdf file URL and let the user download it, it might represent a security risk (you don’t want your user download other generated pdf files).

So it will depend on your setup:

  • If the user is logged in, you might want to save the filename as a user meta using update_field('pdf_files', $pdf_filename, 'user_56') so you can check that the current user has the authorization to the download.
  • If the user is not logged in, then you might want to generate a unique hashed file name using the md5() function (See documentation). But it can still represent a risk as an other user might guess file name.
  • An another method, which is the most safe, is to send the PDF to the user as an email attachment using wp_mail() (See documentation) during the form submission. So the user never has access to the public URL. Additionally, you can delete the file once the mail is sent.

    You can use the Form Email Action for that, generate the PDF and attach the file in the acfe/form/submit/email_args hook. See an another support thread on this topic.

Hope it helps!

Have a nice day!

Regards.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer