Title: Using method Forminator_API::update_form_entry
Last modified: September 3, 2023

---

# Using method Forminator_API::update_form_entry

 *  Resolved [jamminjames](https://wordpress.org/support/users/jamminjames/)
 * (@jamminjames)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/)
 * When using the “Forminator_API::update_form_entry” method, how do you update 
   items that are not simple “name”/”value” arrays?
 * For example, a simple field has an array like:
 *     ```wp-block-code
       [email-1] => Array ( [id] => 67 [value] => test@email.com ) 
       ```
   
 * …and can be updated using entry meta like:
 *     ```wp-block-code
       $entry_meta = array(
          array(
             'name' => $key,
             'value' => $value
          )
       );
       ```
   
 * But what about a field that has a deeper array, like:
 *     ```wp-block-code
       [name-1] => Array ( [id] => 68 [value] => Array ( [first-name] => john [last-name] => testy ) )
       ```
   
 * How do you construct the entry meta for such a field, so that it may be updated?
   Thanks for any help.
    -  This topic was modified 2 years, 9 months ago by [jamminjames](https://wordpress.org/support/users/jamminjames/).

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

 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17027087)
 * Hi [@jamminjames](https://wordpress.org/support/users/jamminjames/)
 * Thank you for your question!
 * To update such data you simply need to serialize it.
 * For example:
 *     ```
       $entry_meta= array(
       	array(
       		'name' => 'name-1',
       		'value' => maybe_serialize( array( 'first-name' => 'test first', 'last-name' => 'test last' ) )
       	)
       );
       ```
   
 * I hope that helps!
 * Best regards,
    Adam
 *  Thread Starter [jamminjames](https://wordpress.org/support/users/jamminjames/)
 * (@jamminjames)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17029099)
 * Thanks. However, I’m having trouble if there is more than one field to update,
   and if one needs to be serialized and one doesn’t. I’ve tried two ways, neither
   is working. With the first, it only updates the serialized field, with the second,
   it only updates the non-serialized, and messes up the form data for the serialized
   field. It’s the same result if I take out the “[]” brackets, which it seem like
   they’re needed, since we need to add to the array for the multiple field updates:
 *     ```wp-block-code
       foreach ($ids_new_arr as $k => $d) {
         if (is_array($d)) {
           $entry_meta[] = array(
             array(
               'name' => $k,
               'value' => maybe_serialize( array( $d ) )
             )
           );
         } else {
           $entry_meta[] = array(
             array(
               'name' => $k,
               'value' => $d
             )
            );
         }
       }
       ```
   
 * and
 *     ```wp-block-code
       foreach ($ids_new_arr as $k => $d) {
         if (is_array($d)) {
            $entry_meta[] = array(
       	'name' => $k,
       	'value' => maybe_serialize( array( $d ) )
            );
         } else {
            $entry_meta[] = array(
       	'name' => $k,
       	'value' => $d
            );
         }
       }
       ```
   
 *  Thread Starter [jamminjames](https://wordpress.org/support/users/jamminjames/)
 * (@jamminjames)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17029238)
 * Okay, I think this is better, but it’s still not updating:
 *     ```wp-block-code
       foreach ($ids_new_arr as $k => $d) {
         if (is_array($d)) {
       	$sub_entry_meta[] = array(
       	  'name' => $k,
       	  'value' => maybe_serialize( array( $d ) )
       	);
         } else {
       	$sub_entry_meta[] = array(
       	  'name' => $k,
       	  'value' => $d
       	);
         }
       }
   
       $entry_meta = array($sub_entry_meta);
       ```
   
 * The array it produces looks like:
 *     ```wp-block-code
       Array
       (
         [0] => Array
           (
             [0] => Array
               (
                 [name] => text-1
                 [value] => testmon
               )
   
             [1] => Array
               (
                 [name] => name-1
                 [value] => a:1:{i:0;a:2:{s:10:"first-name";s:5:"teddy";s:9:"last-name";s:7:"testmon";}}
               )
           )
       )
       ```
   
 * When I run:
 *     ```wp-block-code
       $update_entry = Forminator_API::update_form_entry( $form_id, $do_entry_id, $entry_meta );
       ```
   
 * `$update_entry` returns ‘true’, but the data does not update.
    -  This reply was modified 2 years, 9 months ago by [jamminjames](https://wordpress.org/support/users/jamminjames/).
 *  Thread Starter [jamminjames](https://wordpress.org/support/users/jamminjames/)
 * (@jamminjames)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17031673)
 * P.S. How we get some kind of info on the result of ‘Forminator_API::update_form_entry’?
   Can’t find anything in your documentation about viewing result objects.
 * The documentation says that upon success, ‘Forminator_API::update_form_entry’
   returns the Entry ID that was being edited (not ‘true’ as I’d assumed). However,
   in my case, it returns “1” every time.
    -  This reply was modified 2 years, 9 months ago by [jamminjames](https://wordpress.org/support/users/jamminjames/).
    -  This reply was modified 2 years, 9 months ago by [jamminjames](https://wordpress.org/support/users/jamminjames/).
 *  Thread Starter [jamminjames](https://wordpress.org/support/users/jamminjames/)
 * (@jamminjames)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17031808)
 * Okay, I finally got it. I had the wrong thing in the maybe_serialize function.
   I had “maybe_serialize( array($d) )”, instead of simply “maybe_serialize( $d )”.
   It’s working now. My final PHP code, for anyone interested, is:
 *     ```wp-block-code
       foreach ($field_entries as $k => $d) {
         $serial = maybe_serialize( $d );
         if (is_array($d)) {
           $sub_entry_meta[] = array(
           'name' => $k,
           'value' => $serial
           );
         } else {
           $sub_entry_meta[] = array(
           'name' => $k,
           'value' => $d
           );
         }
       }
       $entry_meta = $sub_entry_meta;
   
       // update entry in db table
       $update_entry = Forminator_API::update_form_entry( $form_id, $do_entry_id, $entry_meta );
       ```
   
 * I’m still curious about how to view result objects though, for info on what happened
   after executing methods like ‘Forminator_API::update_form_entry’.
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17033273)
 * Hi [@jamminjames](https://wordpress.org/support/users/jamminjames/)
 * Thanks for update!
 * I’m sorry for not being able to get back to you earlier but I’m glad you’ve figured
   it out.
 * As for “viewing result objects”, I’m not quite sure if I understand it correctly
   but let me try 🙂 :
 * The “update_form_entry” method only returns entry ID if update successful so 
   there’s no way to “directly” see anything.
 * The entry (as in “submission”) is updated directly in DB so you should see changes
   reflected in “Forminator -> Submissions” but if you want to check it “by code”
   you simply need to use another method after the update the “get_entry()” one,
   passing form ID and that entry ID to it.
 * [https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/#method-get_entry](https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/#method-get_entry)
 * This will fetch and return that entry for you and if you call it after “update_form_entry()”
   it should return already updated one.
 * Best regards,
    Adam
 *  Thread Starter [jamminjames](https://wordpress.org/support/users/jamminjames/)
 * (@jamminjames)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17034106)
 * Okay, thanks. But the “update_form_entry” method does NOT seem to return the 
   entry ID if update successful, it’s always “1”, or “0” if not successful. WPMU
   ought to update that in the documentation.
 *  Plugin Support [Williams – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport3/)
 * (@wpmudevsupport3)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17039701)
 * Hi [@jamminjames](https://wordpress.org/support/users/jamminjames/),
 * Hope this message finds you well and thank you for bringing this to our attention.
 * I did share it with our Devs and Docs team.
 * Best regards,
    Laura
 *  Thread Starter [jamminjames](https://wordpress.org/support/users/jamminjames/)
 * (@jamminjames)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17039717)
 * Well, now I’m not sure. The reason I thought this is that after running
 *     ```wp-block-code
       $update_entry = Forminator_API::update_form_entry( $form_id, $do_entry_id, $entry_meta );
       ```
   
 * … I echo the “$update_entry” variable, and it always shows as “1”. However, when
   I test:
 *     ```wp-block-code
       if ($update_entry==$do_entry_id)
       ```
   
 * … it passes as true, and since “$do_entry_id” is the form entry ID, it would 
   seem that “$update_entry” is returning a match for that. Not sure why it echoes“
   1” though.
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17041751)
 * Hi [@jamminjames](https://wordpress.org/support/users/jamminjames/)
 * Thanks for response.
 * The “update_form_entry()” as it turns out doesn’t return form ID. I was wrong
   on that (and I have already asked our docs team to update API docs as that’s 
   where I took that information from). It actually returns boolean true/false (
   that’s why it “echoes” 1 or 0 always) or WP error instead.
 * However, you actually do need to read the entry ID since you already have it –
   you are updating entry instead of adding new one so ID will be the same. Therefore,
   after update is made you can simply do this
 *     ```
       if ( ! is_wp_error( $update_entry ) ) {
   
       // and here you can e.g. fetch and check the updated entry
   
       }
       ```
   
 * and this should do the trick.
 * Best regards,
    Adam

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

The topic ‘Using method Forminator_API::update_form_entry’ 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

 * [method](https://wordpress.org/support/topic-tag/method/)

 * 10 replies
 * 3 participants
 * Last reply from: [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/using-method-forminator_apiupdate_form_entry/#post-17041751)
 * Status: resolved