Created
September 15, 2017 00:02
-
-
Save Shelob9/bfb3082e47ed63a5004a7579b5ced38d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Use an HTML table to create a Caldera Forms email layout that is roughly the same as form layout | |
* | |
* Work in progress | |
*/ | |
add_action( 'caldera_forms_mailer', function( $mail, $data, $form, $entry_id ){ | |
include_once CFCORE_PATH . 'classes/caldera-grid.php'; | |
$gridsize = 12; | |
$grid_settings = array( | |
"first" => 'first_row', | |
"last" => 'last_row', | |
"single" => 'single', | |
"before" => '<tr %1$s class="row %2$s">', | |
"after" => '</tr>', | |
"column_first" => 'first_col', | |
"column_last" => 'last_col', | |
"column_single" => 'single', | |
"column_before" => '<th %1$s class="col-'.$gridsize.'-%2$d %3$s">', | |
"column_after" => '</th>', | |
'form_id' => $form['ID'], | |
'form_id_attr' => $form['ID'], | |
); | |
$grid = new Caldera_Form_Grid( $grid_settings ); | |
$grid->setLayout( $form[ 'layout_grid' ][ 'structure' ] ); | |
if ( ! empty( $form[ 'layout_grid' ][ 'fields' ] ) ) { | |
foreach ( $form[ 'layout_grid' ][ 'fields' ] as $field_base_id => $location ) { | |
if ( isset( $form[ 'fields' ][ $field_base_id ] ) ) { | |
$field = Caldera_Forms::load_field( $form, $field_base_id ); | |
if( isset( $data[ $field[ 'ID' ] ] ) ){ | |
$value = $data[ $field[ 'ID' ] ]; | |
}else{ | |
$value = Caldera_Forms::get_field_data( $field[ 'ID' ], $form, $entry_id ); | |
} | |
$grid->append( $value, $location ); | |
} | |
} | |
} | |
$html = '<table><tbody>' . $grid->renderLayout() . '</tbody></table>'; | |
$mail[ 'message' ] = $html; | |
return $mail; | |
}, 9, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment