I am trying to pass a value from a CRED form to another field when the user clicks on "submit." Specifically I am trying to pass the url of an embedded video to another custom field when submitting the form via a function. I want the function to work so that users can edit/update the url of the embedded video if they need to in the future and it still pass the value into that other custom field.
Any suggestions?
Hello davidT-17,
Thank you for contact Toolset Support.
I will be happy to help you with your issue.
From your explanation, I am unsure as to how you are trying to pass on the url of the embedded video.
Could you please clarify the following to allow me to understand the issue correctly:
Where is this url coming from? Another input field or somewhere else on the page?
Is this value then saved on the same form in another field or on a different form/page?
A link to the site/page, your current code and screenshots explaining the flow would be extremely helpful in helping us formulate a solution.
Additionally, if required, you can also refer to the CRED API, more specifically to the following hooks cred_save_data and cred_before_save_data to process and save the custom field.
https://toolset.com/documentation/programmer-reference/cred-api
Awaiting your reply.
Kind regards
Thank you Arvish for your help with this.
I have attached some screenshots of where the url is embedded and the metabox we ultimately want the url passed to when saving the form data. We are trying to get a featured image generated from the videos that are embedded so that users have a visual representation of the custom post type when looking at the views.
Hello davidT-17,
Thank you for your reply.
You could use the ‘cred_save_data’ hook to save the another post meta value with one of the form’s values as follows:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==YOUR_FORM_ID)
{
if (isset($_POST['my_video_link_field']))
{
// add it to saved post meta
add_post_meta($post_id, '__my_video_other_link_field', $_POST['my_video_link_field'], true);
}
}
}
Don’t forget to replace ‘YOUR_FORM_ID’ with your CRED form’s ID.
hidden link
Please let me know if this helps.
Kind regards
Thank you Arvish. Giving it a try right now.
Hello davidT-17,
Thank you for your reply.
Let me know if the solution works for me to consider the issue as resolved or if you need further assistance.
Kind regards