Home › Toolset Professional Support › [Resolved] Cred Form Message Title Auto Fill
Problem:
How to Auto Fill post title using CRED form
Solution:
You can use CRED API hook "cred_save_data" to customize post title using CRED form when you submit the form.
You can find proposed solution with the following reply:
=> https://toolset.com/forums/topic/cred-form-message-title-auto-fill/#post-605686
Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
Tagged: Content-submission forms, CRED API, Toolset Forms
Related documentation:
This topic contains 8 replies, has 2 voices.
Last updated by dmitryK-2 6 years, 10 months ago.
Assisted by: Minesh.
Tell us what you are trying to do?
I've created CRED form for Contact Us purposes on my site (can be seen here - hidden link)
Also CPT's (Contact Form) & Custom Fields been created:
tscf-your-name
tscf-email
tscf-phone
tscf-topic-radio (as radio-button, with 1,2,3,4,5 values stored in db)
tscf-comments-questions
I've added code provided in message (##375174) - and my Titles of CPT's "Contact Us" stay blank (not filled) after submitting them on front end - THAT's OK, and shows that code works!
function my_save_data_action($post_id, $form_data){ // Change your CRED Form "ID" accordingly below if ($form_data['id']==ID){ //Declare the content of your variables, change "your_custom_field_slug" accordingly $custom_title = get_post_meta( $post_id, 'wpcf-your_custom_field_slug', true ); //collect data and define new title $my_post = array( 'ID' => $post_id, 'post_title' => $custom_title, 'post_name' => $custom_title, ); // Update the post into the database wp_update_post( $my_post ); } } add_action('cred_save_data', 'my_save_data_action',10,2);
I'm not very strong in php, can you please help me to adjust that code , so my CPT's "Contact Us" Title being filled like this:
"[postid]+ [tscf-your-name]+ [tscf-topic-radio, I mean 1 or 2 or 3 or whatever user will chose]"
Is there any documentation that you are following?
hidden link
https://toolset.com/forums/topic/automatic-post-titles-with-a-cred-form/
Is there a similar example that we can see?
hidden link
What is the link to your site? hidden link
Hello. Thank you for contacting the Toolset support.
Well - I do not able to see the contact form with the link you shared with us:
=> hidden link
is it possible for you to give me access so that I can fix it on your behalf.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Yep fixed (CPT's slug been slightly changed). Now it working. Moment I'll prepare access for you
Can you please set next reply for private again - so I can send you login info/ Thx
I have set the next reply to private which means only you and I have access to it.
Well - wp-admin access details not working. Could you please resend it.
I have set the next reply to private which means only you and I have access to it.
Dear Manesh, are credentials OK?
Yes access details you sent to me in last reply help me to login into wp-admin, so its working.
I've adjusted the code in your functions.php file as given under:
/*Toolset Contact forms*/ function my_save_data_action($post_id, $form_data){ // Change your CRED Form "ID" accordingly below if ($form_data['id']==48859){ //Declare the content of your variables, change "your_custom_field_slug" accordingly $your_name = get_post_meta( $post_id, 'wpcf-tscf-your-name', true ); $topic_id = get_post_meta( $post_id, 'wpcf-tscf-topic-radio', true ); $topic_array = array('1'=>'Задать вопрос','2'=>'Заказать мастер-класс','3'=>'Батчи на заказ','4'=>'Гидролаты на заказ','5'=>'Подарочный набор'); $custom_title = $post_id." - ".$your_name." - ".$topic_array[$topic_id]; //collect data and define new title $my_post = array( 'ID' => $post_id, 'post_title' => $custom_title, 'post_name' => sanitize_title($custom_title), ); // Update the post into the database wp_update_post( $my_post ); } } add_action('cred_save_data', 'my_save_data_action',10,2);
I can see now its working fine and post title build as per your requirement. Could you please confirm.
Yes Sir) Perfect!