Dear Sir/Madam,
I think file upload drag/drop feature has been requested for a long time ago, at least more then 1 year I know. It is must for a site with image gallery, otherwise, upload file one by one is not user-friendly. Some of the sites we have to give up using Toolset as it sill not yet supported the file upload drag/drop feature while it is the requirement for the clients.
Is it possible to have some script for us to record the relationship if we insert other plugins for the drag/drop function? If I can have a custom code to allow a customer to upload the files by drag/drop and return with an id and we can store this id via the CRED, I think it may help to view the gallery by calling the id.
Do you have any suggestion?
Best regards,
Kelvin.
Hi, we currently offer the cred_save_data API that will allow you to save some custom field values when the form is submitted, like this:
$post_id = 12345;
$files = array('<em><u>hidden link</u></em>', '<em><u>hidden link</u></em>', '<em><u>hidden link</u></em>');
foreach( $files as $file ) {
add_post_meta( $post_id, 'wpcf-repeating-image-field', $file );
});
So if you know the file URLs when the CRED form is submitted, you can use this method to update a repeating image field. The problem with using another plugin file to handle uploads is that it may not be easy to save those file URLs somewhere you can access them during cred_save_data. There is no CRED JavaScript API, so I don't have any code to offer to help with that part. I can help you use the add_post_meta function in a cred_save_data hook, if you can provide a variable that holds an array of the uploaded file URLs.
More CRED API documentation here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
Dear Christian Cox,
When I create a post using CRED, is there any post id I can get or I can only get the post id when cred_save_data is performed? If I can have the post id, then I can make a drag/drop associated with the post id.
Best regards,
Kelvin.
There is no new post ID until the CRED form has been submitted and the post has been created, so I'm not sure what you're asking for exactly. If you're asking how to predict the new post's ID before the form is submitted, it is not possible. The cred_save_data hook is probably the first opportunity you will have to access the new post ID. This is the main challenge with using a 3rd-party file uploader as I mentioned earlier:
The problem with using another plugin file to handle uploads is that it may not be easy to save those file URLs somewhere you can access them during cred_save_data.