Resetting all fields in an entry

By: David Costin | Asked: 02/25/2023
ForumsCategory: How-toResetting all fields in an entry
David Costin asked 1 year ago
I want to reset all field values in an entry. I have come across this advice: - <a href="#" onclick="document.getElementById('form_[form_key]').reset();">Reset Form</a> Paste this code in at the end of your "Submit Button" section on your "Customize HTML" Page. No modification is necessary as it will automatically retrieve the proper form_key, however if you use this code elsewhere on a page, you may need to manually enter the field key in place of [form_key]. This code does clear all fields and selections.  However, it only works when you are in the process of completing a new entry.  I want to reset an existing entry.  No matter how I use the above script, it will not work on edit. David
1 Answers
Victor Font answered 1 year ago

I don't think you understand what form.reset() does. What you describe is exactly how it is supposed to work. A reset() reverts changes made during a session and returns the form to its initial values. When you load a form to create an entry, the initial values of your input fields are empty unless you set default values for them. This is why reset() seems to "clear" the form. It isn't really clearing the form, it's resetting the fields to their initial values. When you edit a form, the initial values are the values you entered during form creation. If you change values or clear fields manually when editing a saved entry, reset restores what was there when the form was loaded for editing. If you want to really clear fields on an edit, you have to loop through every field in the fieldset and clear them with code.

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