Hello !
I use this for months/yeasr now on my website to customize the name/title of my form result:
[cred_field field='post_title' value='[wpv-post-title]']
I use the same form in a lot of different pages, this allow me to know from which page the forma as been filled.
However, it seems to still work now 95% of the time but sometimes I have results with a title like
"CRED Auto Draft d0780c1fa2c63b8f3e5a4a338692c043".
I can't link the form to the page it comes from then. Which is really an issue.
Could you please help to find why it acts like this now ? I've made many test myself without being able to reproduce it. But when external users fill them, sometimes it happens.
Is there another way to "flag" the form with the page title it comes from ?
Thanks or your help.
Hi,
Thank you for contacting us and I'd be happy to assist.
To programmatically save the title of the page/post from where a form is submitted, you can add a single line type custom field 'form-submitted-from'.
Next, a custom function attached to the 'cred_save_data' hook can be used to save the form's containing post/page title, in that custom field:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
For example:
add_action('cred_save_data', 'custom_save_form_container',10,2);
function custom_save_form_container($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==12345)
{
// if form container ID is set
if (isset($_POST['_cred_cred_prefix_cred_container_id']))
{
// get the title of the container ID
$container_title = get_the_title($_POST['_cred_cred_prefix_cred_container_id']);
// add it to saved post's target custom field
add_post_meta($post_id, 'wpcf-form-submitted-from', $container_title, true);
}
}
}
Note: You'll replace '12345' with your actual form's ID and 'form-submitted-from' with the slug of your target custom field.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
regards,
Waqar
Hi Warqar.
I thought I did it well but it does not seem to work...
Could you please help more ?
Maybe in taking a look in the backend ?
Thanks for your help.
Fabrice
Hi Fabrice,
To troubleshoot this, I'll need to see how this form and the custom code are set up in the admin area.
Can you please share temporary admin login details, along with the exact steps to test the form?
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
regards,
Waqar
The corresponding script is called "post-title-name" to have the full info.
Thank you for sharing these details.
The custom code has been added correctly, however, the field 'form-submitted-from' has been added as a generic field.
Can you please remove that generic field's code from the form and add a standard single line type custom field with slug 'form-submitted-from', to the post type 'Demandes d'informations'.
After this, the code should work to update the field and to include the value in the form notification.