[Resolved] Failure to save form data derived from generic form fields
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
The difficulty I’ve run into now is related, but the case seems simpler, if anything. I’m building out the user-facing elements for a post-type connected to those I was working on earlier, and I’m using generic select form fields drawing on repeatable-field-group data from a parent in a manner essentially the same as done with success elsewhere in the project. My generic select fields in the current instance display query data correctly, and cred_save_data hook usage is effectively copy of other working functions serving the same purpose elsewhere. In the current instance, however, the generic field form data isn’t getting saved.
Below, the relevant parts of the two form with respective corresponding functions, mostly identical, as I have them at the moment.
I’ve experimented with producing the selection list in different ways, but this seems to have no bearing on the problem. I’ve included "persist":1 and removed it without effect. I’ve also tried variations of the save functions using add_post_meta() and update_post_meta(), again apparently without effect.
I'm not familiar with the work you have done so far, but looking at the code samples you share I can spot an obvious problem. Hopefully fixing that will be all you need.
Types custom fields are stored in wp_postmeta with a 'wpcf-' prefix.
A generic field added to a Toolset Form is not a Types custom field, and hence does not use the 'wpcf-' prefix.
In the examples above you are checking the $_POST object for the field value but you are using the 'wpcf-' prefix.
If, for debugging purposes, you send the $_POST object to the debug.log you should see that the form will contain a value where the key is the field slug without the 'wpcf-' prefix. (However, if you are then trying to update the post meta for a Types custom field with the same slug, then the 'wpcf-' is required.)
Here's how you would send a readable version of an array or object to the debug log:
That was it. I’ve been giving my generic form fields the same slug as the Types custom fields the values get saved to, and didn’t notice that I was muddling the two things in the save function. Corrected, the function in my second example is:
I’ll need to go back and look at hooks I set up previously, apparently working fine, which were copied here. It may be that they’re not working as nicely as I think they are, but that something about my process has obscured the fact.
And I need to attend to the debug log. Your prod to this end is entirely apt.