I have a form with hidden fields to insert values into the custom fields. It works for the first field pick-course but not for the second pick-type. I've tried capitalizing and all lower case but it won't stick. See screenshots.
There is a condition on pick-course which is the Pick Type = course, but I don't see how that matters since that's actually the one that does insert.
Pick-type is a select field and pick-course is an object reference.
Screenshot 1 shows my form. 2 is what the insertion looks like, as you can see it did not take pick type. 3 is when I manually select the pick type and then you can see that the pick-course did insert. 4 and 5 are the custom fields.
Sorry, but I'm really struggling to understand what the issue is here, perhaps you could elaborate further.
I see in screenshot 1 a form which contains nothing more than two hidden generic fields and a submit button.
These are generic fields and so when the form is submitted they are discarded. Which means you presumably are running some code on the server—I would imagine with the cred_save_data hook—to do something based on the submitted field values, otherwise the form does nothing.
Is the problem with the values of these fields when the form is submitted? You are expecting one thing, but getting something else?
Where is the form displayed?
It looks like the pick-course field should have the value of a URL parameter id coming from the url of the page where the form is displayed.
While the second field, pick-type, would always be the default "Course", because there is nothing to set it to be any different.
Could you please expand on what it is you are trying to do with this form and what you expect to happen?
Yes, the course id comes from the URL and it works, it shows the right course selected, in other words, the hidden fields is passed and inserted into the DB.
The pick-course is of field type Course. If I pass another course id, it updates, hence, the hidden field is passed and it works. The same should work for the second field but it does not.
As for what I'm trying to do is pass data on via a hidden field that the user does not need to see and insert it in the Pick Object which works for one of the hidden fields. What do I expect to happen, I expect both hidden fields to be inserted.
Based on what you've shared the second field should also be working. To troubleshoot this, I'll need to see how these fields and the form are set up in the admin area.
Can you please share temporary admin login details and the exact steps to see the issue?
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
1. The default value should be 'course' and not 'Course' because, in the field's setting, we're storing the value as 'course'.
2. The "persist":"1" tells the system that we'd like to save this generic field value to the database. By default, generic field values are not saved in the database and they are used for processing through the custom code, on the form submission.
3. The generic field's slug should be complete with the prefix 'wpcf-' ( i.e. wpcf-pick-type ), because that is how the Tookset Type's defined/registered custom field value is stored in the database.
Note: I can understand that you must be wondering why it is working for the 'post reference' type field, without these steps. The post-reference field's data is technically not stored as a custom field value. It is stored in a post-relationship structure, which would explain its exceptional treatment.