{"id":15706161,"date":"2022-06-03T12:51:49","date_gmt":"2022-06-03T12:51:49","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/custom-code-forminator_form_after_save_entry-called-if-nothing-was-saved\/"},"modified":"2022-06-03T12:51:49","modified_gmt":"2022-06-03T12:51:49","slug":"custom-code-forminator_form_after_save_entry-called-if-nothing-was-saved","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/custom-code-forminator_form_after_save_entry-called-if-nothing-was-saved\/","title":{"rendered":"Custom code. forminator_form_after_save_entry called if nothing was saved?"},"content":{"rendered":"<p>Dear Forminator team,<\/p>\n<p>I&#8217;m having some issues with custom code. Not sure if this is the right place to post this?<\/p>\n<p>We have a form where submissions are sent to an external API. Form submissions are captured as suggested in https:\/\/wpmudev.com\/forums\/topic\/other-how-to-capture-the-submitted-form-data\/ :<\/p>\n<pre><code>\nadd_action( &#039;forminator_form_after_save_entry&#039;, &#039;my_form_submit&#039; );\nfunction my_form_submit( $form_id ) {\n\n    if ( $form_id == THE_FORM_ID ) {\n\n        $entry = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $form_id );\n\n    }\n}\n<\/code><\/pre>\n<p>We also have backend validations, like https:\/\/gist.github.com\/wpmudev-sls\/8ca771c9cde2f583b20280b23291e9cc . Now the problem is that if a validation fails, the entry is not saved, but the hook forminator_form_after_save_entry is called anyway. Which means the last saved entry is processed again, creating a duplicate in the API.<\/p>\n<p>It seems to me that in Forminator_Front_Action -&gt; save_entry() the action is called unconditionally, is that correct?<\/p>\n<p>It is confusing that forminator_form_after_save_entry is called even if nothing was saved. Is it a bug or intended behaviour? If it is intended, is there any way to check if a new entry was saved?<\/p>\n<p>&#8211; Marie-Christine<\/p>\n","protected":false},"template":"","class_list":["post-15706161","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15706161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15706161\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=15706161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}