• Resolved Messaone

    (@messaone)


    Hey.

    Is there any hook after acfe/form/submit/post/form=
    I’m just creating a PDF in this action and customer want to open pdf in a new tap an remove it after it. But the unlink is fast than the browser side echo.

    So I’m looking for a hook after acfe/form/submit/post/form=.
    I also tried transition_post_status but i think that comes before your hook.

    Best Regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    I’m not quite sure to understand what you mean by:

    I’m just creating a PDF in this action and customer want to open pdf in a new tap an remove it after it. But the unlink is fast than the browser side echo.

    The acfe/form/submit/post hook let developers make programmatic changes/update after a post has been udpated/created using a Post Action. You are not supposed to echo anything inside it.

    You can either add a Redirect Action to redirect the user to a specific page, and use Template Tags or PHP Redirect hooks to retrieve a custom value. Or directly perform a header('Location: /my-redirect'); exit; in the Post Action hook (which will stop any other actions too), but not echo anything.

    If you want to hook after that action, you can either add an higher hook priority, like 99 (See WordPress hooks documentation), or use the general acfe/form/submit hook which is performed after all forms actions have been processed. See documentation. But I don’t think that will fix your issue, as you should probably delete the PDF file when you made sure the user correctly downloaded it for example.

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter Messaone

    (@messaone)

    I tried to set like you wrote. I tried the acfe/form/submit hook.

    Here is my code (not all i remove some mail bode parts.

    add_action('acfe/form/submit/post/form=create-pdf', 'pdf_submit', 10, 5);
    function pdf_submit($post_id, $type, $args, $form, $action){
    
    // create pdf
    require_once 'pdf-create.php';
    
    $customer_mail = get_field( 'e-mail_adresse' );
    $customer_company = get_field( 'firma' );
    $support_mail =  'mail@domain.com';
    $emails      = array ($customer_mail, $support_mail);
    $body = '<table></table>';
    
    // created in the pdf_create.php
    $attachments = array(WP_CONTENT_DIR . '/uploads/pdf/'.$pdf_file );
    
    wp_mail( $emails, 'PDF: '.$post_id.' Customer '. $customer_company, $body, $headers = '', $attachments);
    
    // add PDF do DB -> for delet if published
    foreach ( (array)$attachments AS $file ) {
        if ( ! add_post_meta( $post_id, 'pdf_file', $file, true ) ) { 
            update_post_meta ( $post_id, 'pdf_file', $file );
            }
    }
    
    //Open a new window with the file
    echo '<script> window.open("https://wwww.domain.com/wp-content/uploads/pdf/'.$pdf_file.'", "_blank");</script>';
    
    	
    }
    
    // should remove file - don't work
    
    add_action('acfe/form/submit', 'my_form_submit', 99, 2);
    function my_form_submit($form, $post_id){
        
    	$pdf_file = get_post_meta( $post_id, 'pdf_file', true );
    	wp_delete_file( $pdf_file );
        
    }
    • This reply was modified 2 years, 9 months ago by Messaone.
    • This reply was modified 2 years, 9 months ago by Messaone.
    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    The $post_id in the general acfe/form/submit hook is the post ID of the page where the form is rendered, as explained in the documentation.

    To retrieve the Post Action output (ID, title, author…) in an another action, or a general hook, you have to use the acfe_form_get_action() function. See documentation.

    But as explained in my previous answer, you should not echo anything in a Post Action, as it will potentitally break next actions.

    Also, your logic is flawed, because the PDF will be deleted before the browser can render it. Even if the client was fast enough, that would mean clients with slow Internet speed will not be able to see the PDF (as the server is faster). You should just print the PDF url on the success page/client area, and cleanup files using a cron for example.

    Regards.

    Thread Starter Messaone

    (@messaone)

    Yeah – that was my second thought clean up all 5 mins the folder – You are right – In case of slow internet there is no change to see the pdf.

    I will do it like you recommend – I will add a action after the form with a button for clients to get the file.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Okay, good. You’ll find an example of how to customize the success page and retrieve information from submitted Actions on the Form Helpers documentation.

    Have a nice day.

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hook after acfe/form/submit/post/form=’ is closed to new replies.