Tagged: bug, hidden field, repeater field
- This topic has 1 reply, 2 voices, and was last updated 5 years, 3 months ago by
Steve.
-
AuthorPosts
-
-
October 27, 2016 at 1:26 pm #7463
rickParticipantHi,
I have been noticing this strange behavior when using a repeater field with a hidden field. In a nutshell, I created a settings page which is designed for a user to add in store locations (as many as they need). I have a location_id hidden field, which before saving to the database, I will programmatically fill in with a unique ID. When defining the field group, I specify a default value of ‘null’ for the location_id field. Then, when the piklist_pre_update_option filter is fired, I will iterate through each location, check if the location_id field is null, and if it is, do what needs to be done to calculate the location ID.
The first field, this works great and as expected. However, once a second field is created, the default ‘null’ value does not occur… in fact, the default value appears to somehow get cloned from whatever the first location’s entry is, which should not be the case.
To demonstrate this, I created a little demo bug plugin which you can try attached. To simulate the “generate location id” process, I replaced this with a wp_rand call, which is unlikely to product the same number back to back.
To replicate this issue, do the following:
1. Install Piklist and the “Hidden Field Bug” plugin (attached)
2. Navigate to the newly created “locations” settings page
3. Make up a location name – such as “Location 1” and press “Save Location Information”
4. Log into the WP Database (through phpMyAdmin or however you prefer).
5. Run SQL Query [code]SELECT * FROMwp_optionsWHEREoption_name=’demo_store_locations'[/code] (make sure you set your specific wp_ prefix for tables)
6. Note the unique location_id generated in this serialized array. If you have trouble viewing the serialized data, use a site like https://www.functions-online.com/unserialize.html to unserialized this data.
7. Go back to the Locations page in the WP-Admin, add a new location such as Location 2.
8. Repeat the SQL query, and note that the location_id is the same for both locations. If you want to rule out the ‘possibility’ that there was a number collision from the wp_rand() function used to generate location_id in this demo, keep adding in new locations and notice that the value is the same.Let me know if you have any questions, and looking forward to hearing back from you.
Bug Demo Plugin: https://dl.dropboxusercontent.com/u/31824171/hidden-field-bug.zip
Rick
-
October 30, 2016 at 9:52 pm #7466
-
-
AuthorPosts
- You must be logged in to reply to this topic.