Default values resetting when updating a current entry?

By: Dave Vance | Asked: 02/24/2023
ForumsCategory: How-toDefault values resetting when updating a current entry?
Dave Vance asked 2 years ago
New user; I did not see this already addressed in the community.   Am I using default values wrong?  I am using a hidden Autonum field to increment a counter (i.e. [auto_id start=1]) that then appends onto the Default Value for a separate hidden Text field creating a unique record id for the entry (the Default Value for that Text field is MEMB-[35] where 35 is the Autonum field id).     This works fine when the entry is first created, but when I bring up a page to edit the existing entry the hidden Autonum field becomes blank and the Text field re-appends this blank onto the record id thus destroying the original entry for both fields.     I would have thought default values would only be triggered when the entry was first created or if the given field was blank?  I have hidden these two fields already so they aren't displaying during the entry update but they get recalculated anyway.  
4 Answers
Jane OnoratiJane Onorati answered 2 years ago
Dave,  This sounds like the same issue I have had using a random function to calculate a value.  See this string for more info: https://connect.formidableforms.com/question/category/how-to/random-calculated-field-value-changes-on-entry-update/
Victor Font answered 2 years ago
When you edit an entry, there's a hidden field named frm_action. When editing, this field has a value of "update" put a check in your formula that tests for this value. If the value exists, don't run the code that appends the autonum.
Dave Vance answered 2 years ago
Thank you Jane and Victor both!  Following your suggestions I explored the hooks and I replaced the auto-id default for that field in the form with a hook to frm_get_default_value to run the auto-id shortcode for that field id.   The comment in the Docs that frm_get_default_value only runs for new entries and not for editing appears to be accurate, as the auto-id now takes place when the entry is first created and does not change when subsequently editing the entry later.   Problem solved. Thanks again!
Michael Tidbury replied 12 months ago

Hi Dave, can you explain exactly what you did because I have the same problem. My default was [auto_id start=7005] and it was a calculated field. I changed it to TEXT (see Chris' comment below) and it still updated on edit.

Do you mean you added a code snippet with the PHP code for frm_get_default_value? I don't see how to access the hidden field frm_action to test if it is update before applying the auto_id.

Thanks, Michael.

Chris Titus answered 2 years ago
I have found that formulas added as Default Value (Calculation) will overwrite any changes I've made to those fields in a specific entry when the entry is updated.  However, if the formula is added as Default Value (Text), updates to the entry do not overwrite any changes I've made to that field in the entry.
Chris Titus replied 2 years ago

This also applies to numbers being added, not just formulas. For example, if I have a default price, but I want to change it for a specific client. It must be added as Default Value (Text).

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right