Hi @danidada
I hope you are doing well.
You will need to use the Forminator_CForm_Front_Mail() class and then the process_mail() function.
But note that custom coding is outside our support scope, for that, you’ll need to hire a developer to provide the required custom code for you. WordPress provides a jobs directory here https://jobs.wordpress.net/, if you need further advice about it, feel free to email [email protected].
Subject: ATTN: WPMU DEV support – wp.org
Best Regards
Patrick Freitas
Hello Patrick,
I am using the class and function you mentioned but the data sent in the notification is the “old” data, not the updated entry data. I have used the same code as in the plugin.
// this one is the code updating the field value
Forminator_API::update_form_entry( $form_id, $entry_id, array( array('name'=>'hidden-3', 'value'=>"si") ) );
$error = '';
if ( isset( $entry_id ) ) {
$forminator_mail_sender = new Forminator_CForm_Front_Mail();
$entry = new Forminator_Form_Entry_Model( $entry_id );
if ( empty( $entry->form_id ) || ! empty( $entry->draft_id ) ) {
$error = esc_html__( 'Entry ID was not found.', 'forminator' );
}
$module_id = $entry->form_id;
Forminator_Front_Action::$module_id = $module_id;
Forminator_Front_Action::$module_object = Forminator_Base_Form_Model::get_model( $module_id );
// Emulate Forminator_Front_Action::$prepared_data.
Forminator_Front_Action::$prepared_data = recreate_prepared_data( Forminator_Front_Action::$module_object, $entry );
// Emulate Forminator_Front_Action::$hidden_fields.
if ( ! Forminator_Front_Action::$module_object ) {
$error = esc_html__( 'Error: Module object is corrupted!', 'forminator' ) ;
}
Forminator_Front_Action::$module_settings = method_exists( Forminator_Front_Action::$module_object, 'get_form_settings' )
? Forminator_Front_Action::$module_object->get_form_settings() : Forminator_Front_Action::$module_object->settings;
Forminator_CForm_Front_Action::check_fields_visibility();
$module_object = Forminator_Base_Form_Model::get_model( $module_id );
// printed data is the updated one
var_dump($entry);
//data sent by mail is the old one
$forminator_mail_sender->process_mail( $module_object, $entry );
Just to get you an update on the code I’m testing. Now it reflects new value on email notification content BUT it doesn’t fire if there is a condition based on the updated field value.
//the update
Forminator_API::update_form_entry( $form_id, $entry_id, array( array('name'=>'hidden-3', 'value'=>"si") ) );
$error = '';
if ( isset( $entry_id ) ) {
$get_data_from_entry = $this->data_from_enty($entry);
$submitted_data = Forminator_Core::sanitize_array( $get_data_from_entry );
// Send email.
$custom_form = Forminator_Form_Model::model()->load( $form_id );
if ( ! is_object( $custom_form ) ) {
$error .= json_encode(
array(
'message' => apply_filters(
'forminator_draft_invalid_form_id',
esc_html__( 'Invalid form ID.', 'forminator' ),
$form_id
),
)
);
}
$forminator_mail_sender = new Forminator_CForm_Front_Mail();
$draft_entry = new Forminator_Form_Entry_Model( $entry_id );
// just to check var_dump($draft_entry);
Forminator_Front_Action::$prepared_data = array_replace( Forminator_Front_Action::$prepared_data, $submitted_data );
$mail_sent = $forminator_mail_sender->process_mail( $custom_form, $draft_entry );
}
Can you please tell me what I am missing? Just ANY condition stop the notification from being sent, also for fields that wasn’t updated.
-
This reply was modified 3 hours, 32 minutes ago by
danidada.
-
This reply was modified 3 hours, 4 minutes ago by
danidada.