Filters and hooks

Data processing

The plugin allows you to override the way data is saved. If save form data is turned on, it saves the data to its own database by default. However, the save procedure can be overwritten.

In the following example, the information you provided when filling out the form is saved as your own custom post type entry:

functions.php:

function my_save_data_action($options, $data) {
    // $form_to_pdf_891_saved_data --> successful save flag: must be set to true or false 
    global $wpdb, $form_to_pdf_891_saved_data;
    
    // $options --> array, Form call parameters from shortcode
    // $data --> array, the information provided in the form
    
    $id = wp_insert_post(array(
            'post_title'  => $data['title'], 
            'post_type'   => $options['post_type'], 
            'post_status' => 'publish'
        ));
    if (!empty($id)) {
        add_post_meta($id, 'my_meta',   $data['meta']);
    }
    
    // If the save was successful
    $form_to_pdf_891_saved_data = true;
}

if (has_action('form_to_pdf_save_data_action')) {
    remove_action( 'form_to_pdf_save_data_action', 'form_to_pdf_891_save_data_action' );
    add_action( 'form_to_pdf_save_data_action', 'my_save_data_action', 10, 2);
}

Change recipients

It is possible to change the recipients via a filter, even based on the filled in data:

functions.php:

function my_form_to_pdf_modify_to($to, $data) {
    
    // $data (array) -> Data completed on the form
    // $to (array)   -> An array of recipients (email addresses)

    $addresses = array();
    $users = get_users('role='.$data['usergroup']);
    foreach ($users as $user) {
        if (!in_array($user->user_email, $to)) {
            $to[] = $user->user_email;
        }
    }    

	/* OR */
	
    $to = array('info@my_domain.com');
    
    return $to;
}
add_filter('form_to_pdf_modify_to', 'my_form_to_pdf_modify_to', 10, 2);

Set of hidden copy recipients

Possibility to send a blind copy to recipients via filter – even based on the filled in data:

functions.php:

function my_form_to_pdf_modify_bcc($data) {
    
    // $data (array) -> Data completed on the form

    $bcc = array();
    $users = get_users('role='.$data['usergroup']);
    foreach ($users as $user) {
        $bcc[] = $user->user_email;
    }    

	/* OR */

    $bcc = array('info@my_domain.com');
    
    return $bcc;
}
add_filter('form_to_pdf_modify_bcc', 'my_form_to_pdf_modify_bcc', 10, 1);
Please note that the codes above is incomplete, for illustration only.