I have a front-end CRED form for creating a custom post. One of the fields in the custom post is an image which is set to allow multiple instances. I would like the user to be able to enter a title and caption for each image uploaded, which should be associated with the image as the post_title and post_excerpt in the wp_posts table just as it would be if the media were edited from the back end.
So, I guess I see two steps here. First, I need two new text fields to appear next to the upload button when the user clicks the "Add New" link on the post form.
Second, I'm not sure how or if the CRED form will correctly save the additional data in the database. I don't want this new data associated with the parent post, but with the image. I'm guessing I'll have to write some additional code that will hook into something like cred_save_data?? Or maybe there's something easier.
Surely this has been done before. Can you give me a little direction or direct me to any sample code or other threads that discuss this?
Thanks
Dear Alan,
There isn't such a built-in feature within CRED form, if you agree, we can take it as a feature request.
Currently, I suggest you setup a child post type for the images, for example "child image post type", with three custom fields:
1) Custom image field
2) custom single line field "caption"
3) custom single line field "title"
After the user created a custom post, display a CRED form for creating the child image post.
See our document:
CRED Forms for Child Content
https://toolset.com/documentation/user-guides/#cred-topics
Creating Groups of Repeating Fields
https://toolset.com/documentation/user-guides/creating-groups-of-repeating-fields-using-fields-tables/
Thanks for your response.
I definitely agree this should be a feature request. Captions and titles on images are standard in WordPress, so probably lots of people would want to do something like this.
As far as a current work-around, I have successfully created a child post with the image, title and caption. As a first test, I used the backend to create a custom post and I liked how the child post options appeared at the bottom of the page after I saved a draft (though, I'd rather not have to save a draft first). I was able to successfully create a test post with several attached images including titles and captions which I rolled into a slideshow at the top of the post view page.
Now, I would like to do this on the front end using a CRED form so that users may upload their own posts based on my custom parent post setup and then attach several photos (child posts) with captions and titles. I would like it to all happen on the same page, not link to separate pages as you suggest. It doesn't seem to be very straight forward. I found this: https://toolset.com/forums/topic/cred-forms-for-child-content-on-original-parent-post/ which seems to be the same problem I am trying to solve, but the discussion is somewhat old (2-4 years ago). Are the suggestions in that forum discussion still valid?
Thanks.
Form within form isn't supported by HTML standard, you can not put the CRED form for creating child post inside the CRED form for creating/editing parent post:
https://stackoverflow.com/questions/3430214/form-inside-a-form-is-that-alright
So, as I mentioned above please follow our document to setup the CRED form for creating child post:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/
It is very simple to do it:
1) Put the "CRED form for creating child post" into a page
2) In the "CRED form for creating/editing parent post", display a link to above page for user to create new child post.
Thanks for your reply. Unfortunately, that solution won't meet our needs. We'll have to come up with another work around unless you add the feature request in the future.
Thanks.