Home › Forums › Backend Issues (wp-admin) › New field type: how to save data
Hi there,
Great work on the plugin, using it a lot here.
I created a new field type called “interactive_images” following your guide at http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/.
My new type gets recognized and I can apply it succesfully in a post.
I’ve also build the back-end form to filled in by the user, which looks like this for several rows: http://d.pr/i/O2m6
My main question is: how do I get data from there, into the database?
The tutorial unfortunately ends where I need more information.
I’ve created the UI inside the function create_field( $field ) {}
in HTML/PHP, but how to save the chosen values to the database?
This is what I’ve got so far: https://gist.github.com/jelmerdemaat/7661494
Thanks in advance,
Jelmer
Hi @Jelmer
Have you tried to simply save the post and see what goes into the DB?
Looking at the code, it seems that all the data will be nicely formated into a nested array, so ACF will save it as a serialized array and give this back to you when ACF leads the value.
Perhaps some testing is needed on your end to determine if and where there is a problem.
Thanks
E
Hi @elliot,
These fields appear correctly as I have filled in: http://d.pr/i/GIJQ
But my own field interactive_image is not even there.
I have a feeling I’m missing a step, but where?
Could it be because I added the new field type it to an existing content part?
Best regards,
Jelmer
Hi,
Everything seems to work better now that I have adjusted the values for name and value:
'name' => $key.'[interactive_image_tag'.$tagnr.'][top]', 'value' => $field['value']['interactive_image_tag'.$tagnr]['top']
Now things do get saved to the database. I have a new field[‘value’] array that is filled with the data. But something with the default values is still going wrong.
When I use the reference to the defaults, I always see the default value.
When I use the reference to the real values, I don’t get the default fallback.
I have applied $field = array_merge($this->defaults, $field);
.
Updated code is at https://gist.github.com/jelmerdemaat/7661494
Hi @Jelmer
I don[t quite understand the problem with the $defaults array, but perhaps you could debug your code line by line to specify which line is not correct and why.
Thanks
E
The topic ‘New field type: how to save data’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.