Skip to content

Instantly share code, notes, and snippets.

@kjohnson
Created February 17, 2017 19:58
Show Gist options
  • Select an option

  • Save kjohnson/6c37c8430a4536fd04b1633526e5202a to your computer and use it in GitHub Desktop.

Select an option

Save kjohnson/6c37c8430a4536fd04b1633526e5202a to your computer and use it in GitHub Desktop.
Add {all_fields_with_values} merge tag to Email Actions
<?php
//...
add_filter( 'ninja_forms_action_email_message', 'kbj_nf_email__all_fields_with_values', 10, 3 );
function kbj_nf_email__all_fields_with_values( $message, $data, $action_settings ){
if( isset( $data[ 'fields' ] ) && ! empty( $data[ 'fields' ] ) ){
$table = '<table>';
foreach( $data[ 'fields' ] as $field ){
if( ! isset( $field[ 'value' ] ) || empty( $field[ 'value' ] ) ) continue;
$label = ( isset( $field[ 'settings' ][ 'label' ] ) ) ? $field[ 'settings' ][ 'label' ] : '';
$table .= "<tr><td>{$label}:</td><td>{$field[ 'value' ]}</td></tr>";
}
$table .= '</table>';
} else {
$table = '';
}
return str_replace( '{all_fields_with_values}', $table, $message );
}
@kjohnson
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment