Title: Forminator API &#8211; submit form
Last modified: May 23, 2022

---

# Forminator API – submit form

 *  Resolved [koulouridis](https://wordpress.org/support/users/koulouridis/)
 * (@koulouridis)
 * [4 years ago](https://wordpress.org/support/topic/forminator-api-submit-form/)
 * Hello, I’ve searched the forum for custom submit actions with Forminator, but
   I couldn’t find a solution to my problem.
 * The problem at hand is:
 * I need, when a user submits a form, to save all the fields’ data to an array,
   so I can later push the data with wp_remote_post to an external API.
 * I’m stuck at how can I check if a user submitted that form with Forminator in
   PHP and when the user submits it how to store all the fields’ data in an array.
 * ALSO – I’m using a snippet plugin to add a snippet of PHP in that specific form,
   is that the best practice?
 * Thank you in advance!
    -  This topic was modified 4 years ago by [koulouridis](https://wordpress.org/support/users/koulouridis/).

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [4 years ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-15669917)
 * Hi [@koulouridis](https://wordpress.org/support/users/koulouridis/)
 * I hope you’re well today and thank you for your question!
 * > I need, when a user submits a form, to save all the fields’ data to an array,
   > so I can later push the data with wp_remote_post to an external API.
 * You can use this action hook
 * `forminator_form_after_save_entry`
 * For example:
 *     ```
       add_action( 'forminator_form_after_save_entry', 'my_function', 10, 1);
       function my_function( $form_id ) {
   
       // do something here
       // e.g. you can get last entriy (submission) for the form of $form_id ID
       // using Forminator API https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/
       }
       ```
   
 * > ALSO – I’m using a snippet plugin to add a snippet of PHP in that specific 
   > form, is that the best practice?
 * It’s fine though personally I always prefer to add custom code as [MU plugin](https://wordpress.org/support/article/must-use-plugins/)
   as it seems safer and less depending on any additional code.
 * Best regards,
    Adam
 *  Thread Starter [koulouridis](https://wordpress.org/support/users/koulouridis/)
 * (@koulouridis)
 * [4 years ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-15670040)
 * Thank you for quick reply!
 * I have a noob question. Here it is:
 * Let’s say I want to get the latest submission of that specific $form_id.
 * The only thing I’ve found in the documentation was how to get a specific entry
   for that form (Forminator_API::get_entry function).
 * That function does not return the latest entry, but a specific entry.
 * How can I modify the function to get the latest only?
 * Also, by getting the latest entry, does that mean every time a user clicks submit,
   the latest entry is the one that he just made?
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [4 years ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-15670456)
 * HI [@koulouridis](https://wordpress.org/support/users/koulouridis/)
 * The “get_entry()” method does return a specific entry and requires both form 
   ID and entry ID but we don’t know the entry ID inside the hook that I suggested.
 * The “get_entries()”, however, returns all entries and that would work because
   you can then just take the one with the highest ID out of it and that’d be your
   recent/latest one.
 * **However:**
 * I was “re-thinking” this and I think it’s not the “best” solution because you
   would still need to fetch all submissions (which may be resource-intensive) and
   there is a slight possibility that the “latest entry” fetched this way would 
   belong to other user (if many users submit the form at the same time).
 * So alternative approach (and simpler) would be to instead use this action hook:
 * _forminator\_custom\_form\_submit\_before\_set\_fields_
 * because it already includes submission data out of the box (so you are sure it’s
   this specific submission) and spares you unnecessary DB operations (like fetching
   all entries). Basic example:
 *     ```
       add_action( 'forminator_custom_form_submit_before_set_fields', 'my_function', 10, 3);
       function my_function( $entry, $form_id, $form_data_array ) {
   
       // do something here
       // you got submitted data in $form_data_aray
       // you also have entire "submission" as object in $entry if needed
   
       }
       ```
   
 * I think this should work for you better and should be easier to use as $form_data_array
   is just a standard array “ready to use” in your code.
 * Best regards,
    Adam
 *  Thread Starter [koulouridis](https://wordpress.org/support/users/koulouridis/)
 * (@koulouridis)
 * [4 years ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-15670522)
 * Thank you for helping me out!
 * I’m still a little confused with Forminator functions, I tried using them, and
   I’m pretty sure I failed to call them correctly.
 * To call this function (forminator_custom_form_submit_before_set_fields) what 
   do I need to do?
 * Do I just add a shortcode to that function and then paste the shortcode at my
   page under the form shortcode?
 * (I’m using a custom PHP file and I write all the functions there, is that the
   wrong approach?)
 * Also, about clicking the submit button, do I need to add logic for that or does
   the function know that the user submitted a form and starts the action?
 * In case I need to add logic behind clicking the submit button please show me 
   how.
 * (I’m interested in two things, trigger an action when submitting a form and getting
   all the field values of a form)
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [4 years ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-15673699)
 * HI [@koulouridis](https://wordpress.org/support/users/koulouridis/)
 * Thanks for response!
 * It’s not a regular function but an [action hook](https://developer.wordpress.org/plugins/hooks/).
 * To use it, you need to run your own “callback function”. This is exactly the 
   example code that I shared previously:
 *     ```
       add_action( 'forminator_custom_form_submit_before_set_fields', 'my_function', 10, 3);
       function my_function( $entry, $form_id, $form_data_array ) {
   
       // do something here
       // you got submitted data in $form_data_aray
       // you also have entire "submission" as object in $entry if needed
   
       }
       ```
   
 * So to start with:
 * 1. create an empty file with a .php extension (e.g. “my-forminator-custom-code.
   php”)
    2. put this as first line of that file
 * `<?php`
 * 3. below it past the code that I shared
 * 4. upload it to the “/wp-content/mu-plugins” folder of your site’s WordPress 
   install.
 * This is a start. At this point whenever user submits form, forminator code will
   do “forminator_custom_form_submit_before_set_fields” action which, in turn will
   execute your custom callback function which is “my_function()” function in example
   above.
 * You won’t see anything yet because the “my_function()” doesn’t do anything – 
   there’s no any code inside it.
 * To make it do something (for example, as you mentioned in your first post, to“
   push the data with wp_remote_post to an external API.”) you need to write your
   own code and put it inside the “my_function()” function.
 * So it doesn’t require any changes in form settings (any additional “logic”, shortocdes
   etc) but inside the “my_function()” function you should put your own PHP code
   that does “something” with $form_data_array(). It may be saving it file or pushing
   it to external API – that’s up to you but you need your own custom PHP code in
   that place.
 * Kind regards,
    Adam
 *  Thread Starter [koulouridis](https://wordpress.org/support/users/koulouridis/)
 * (@koulouridis)
 * [4 years ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-15673739)
 * Hey Adam!
 * Thank you for your patience!
 * I’ve created the mu-plugins folder, I created a custom PHP file, I pasted the
   code you sent me, I also added a print logic.
 * The photo below is not from that script but from a plugin that inserts snippets,
   I tried using both, the forementioned plugin and your way, none of them seem 
   to return the values.
 * [https://prnt.sc/nof9pcPO0vLb](https://prnt.sc/nof9pcPO0vLb)
 * What is the mistake here, and I can’t seem to be able to print the field values?
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [4 years ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-15678275)
 * Hi [@koulouridis](https://wordpress.org/support/users/koulouridis/)
 * Thanks for response.
 * It won’t print anything like that but you can use WP debugging to see data:
 * – enable debugging by adding this lines to the “wp-config.php” file
 *     ```
       define( 'WP_DEBUG', true );
       define( 'WP_DEBUG_LOG', true );
       define( 'WP_DEBUG_DISPLAY', false );
       ```
   
 * – then replace this code of yours
 *     ```
       echo '<pre>';
       print_r($form_data_array);
       echo '</pre>';
       ```
   
 * with this
 * `error_log( print_r( $form_data_array, true ) );`
 * – submit the form and check “debug.log” file on server in “/wp-content/” folder
 * You should see the array with data printed out there.
 * Note please that this entire code is for further “re-use” of data, like e.g. 
   sending it to external API. Printing it out right on the page would be a different
   thing and would require more and different code.
 * Kind regards
    Adam
 *  [plgupa](https://wordpress.org/support/users/plgupa/)
 * (@plgupa)
 * [4 years ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-15686341)
 * Hi Adam,
 * Thanks for the great replies on this thread. You have taught here more wordpress
   functionalities than I have learnt from YouTube, blogs etc.
 * Keep helping with your amazing answers. They are really helpful for new developers
   like me.
 * Thanks
 *  Thread Starter [koulouridis](https://wordpress.org/support/users/koulouridis/)
 * (@koulouridis)
 * [3 years, 12 months ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-15706497)
 * Hello again,
 * I’m fairly new to using custom functions, so I guess the fault here is mine.
 * Sadly, after extensive testing, I haven’t been able to get this to work…
 * Thank you for your patience once again!
 *  [danielgomesmoura](https://wordpress.org/support/users/danielgomesmoura/)
 * (@danielgomesmoura)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-16086317)
 * [@koulouridis](https://wordpress.org/support/users/koulouridis/) try using javascript
   to get the activated value of the fields once the submit is
 *  Thread Starter [koulouridis](https://wordpress.org/support/users/koulouridis/)
 * (@koulouridis)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-16087509)
 * Hey nvm tried a bunch of different things, eventually I created my own plugin
   using js and php.
 *  [Advex](https://wordpress.org/support/users/totalfly/)
 * (@totalfly)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-16501918)
 * Hi,
 * i have a problem to create a simple form to login to an existing external API.
 * i need just 2 simple field: username and password. When the user fill this 2 
   fields and click on submit he must be logged and redirect to the external website.
   I read the API documentation but i didn’t find anything about how to connect 
   it to an existing form, i have just the api credentials and the php script but
   the page still giving me the error “missing parameters”.. can you give to me 
   any idea please?
 * thanks a lot
 *  Plugin Support [Patrick – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport12/)
 * (@wpmudevsupport12)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-16505772)
 * Hi [@totalfly](https://wordpress.org/support/users/totalfly/)
 * I hope you are doing well.
   We will need to verify your code to give a more accurate
   response but per forum rules we don’t spam the thread starter, can you please
   create a new ticket so we can take a closer look?Best RegardsPatrick Freitas

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Forminator API – submit form’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [form](https://wordpress.org/support/topic-tag/form/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [submit](https://wordpress.org/support/topic-tag/submit/)

 * 13 replies
 * 6 participants
 * Last reply from: [Patrick – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport12/)
 * Last activity: [3 years, 3 months ago](https://wordpress.org/support/topic/forminator-api-submit-form/#post-16505772)
 * Status: resolved