Following on from ticket #1572965
We have created a separate CPT to collect Inquiry submissions for another CPT
We would like to collect some information from the post in a Hidden field on the Inquiry form, that is then used on the email notification
Is this possible in the drag and drop mode or do we need to add custom code to the expert mode?
Hello and thank you for contacting the Toolset support.
You can add generic fields with the user interface. But to hide them you will need to switch to the expert mode. If the fields are hidden on the frontend how would you enter values on them? Here too, you will need to switch to the expert mode and enter a value for the hidden fields with shortcodes.
I hope this answers your question. Let me know if you have any doubts.
Okay we switched to expert mode and add the below hidden field:
[cred_generic_field type='hidden' field='room-name-number']
{
"default":""
}
[/cred_generic_field]
We added this to the notification
Room no: [types field='room-name-number'][/types]
But the room no. is coming through blank when we receive the email notification
You will need to pass a value to "default" in your code:
[cred_generic_field type='hidden' field='room-name-number']
{
"default":"[shortcode here to pass the value to this generic field]"
}
[/cred_generic_field]
It is hard to tell without knowing your current setup.
I run a small test locally to suggest a solution. For a custom post "Products", I want to add an Inquiry form. The form will create an Inquiry post and will send a notification to the administrator.
I did not use a generic field because I will need to persist in the product_id on each inquiry post. I used a custom field product-id and I hide it using CSS (style="display: none;"). Then I passed the ID of the product as a value for the field.
Here is the code from my form:
<div style="display: none;">[cred_field field='product-id' value='[wpv-post-id id='$current_page']']</div>
And I was able to display the product id and link on the notification email with the following:
Product : ([types field='product-id' output='raw'][/types]) [wpv-post-link item="[types field='product-id' output='raw'][/types]"]
I hope this helps. Let me know if you still need more information.
Okay I tried -
[cred_generic_field type='hidden' field='room-name-number']
{
"default":"[types field='room-name-number'][/types]"
}
[/cred_generic_field]
and also tried the css code -
Form:
<div style="display: none;">[cred_field field='room-name-number' value='[wpv-post-id id='$current_page']']</div>
Notification:
Room no: [types field='room-name-number' output='raw'][/types]
But it's still not coming through to the notification
In my test, I created a custom post field and used it instead of the generic field. Because we need the information to be persisted and used by the notification. Generic fields are not persisted, so they are mostly useful for custom coding hooks for the submission process.
For this case, we need to retrieve the information on the notification, for that reason, we need to persist it inside a custom field.
Does it make sense? If you still have doubts, please allow me temporary access to your site to check it further. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
Thank you for the credentials. I understand the issue now and I have fixed it.
First, you have been using a Gravity Form on your content template instead of a Toolset Form. Check this screenshot hidden link
I changed it and used the Toolset Form with a shortcode.
Then, I reused the "Room Name/Number" custom field on the custom post type "Space form entries". Then I removed the generic field and used the field "room-name-number". In its value, I added both, the value of custom field "Room Name/Number" from the "Available Space" and the post ID. Check the email on this screenshot hidden link
I hope this helps. Let me know if you have any questions.
Hi Jamal, thats great! thanks for looking into that and finding the fix.
Yes the gravity for is the current form that we'll be replacing with the toolset one, once it has all the hidden fields added that we require. I had put the code for the toolset form for right at the very bottom of the page to be less visible whilst we test it.
So to confirm it was the value that was missing? the code I had added previously need to be changed from this
<div style="display: none;">[cred_field field='room-name-number' value='[wpv-post-id id='$current_page']']</div>
to this
<div style="display: none;">[cred_field field='room-name-number' value='[types field='room-name-number' item='$current_page'][/types][wpv-post-id id='$current_page']']</div>
If we wanted to do the same with a taxonomy term, how would we edit the above code show a taxonomy term in the notification?
You can use any of Views shortcodes that you can find here https://toolset.com/documentation/user-guides/views/views-shortcodes/
Just remember to use item='$current_page', this way, the shortcode will pull data from the parent page, in this case it is the visited available-space.
The shortcode should go into the value="" of the field.
For taxonomy terms, you can use the [wpv-post-taxonomy] shortcode. Check all its attributes here https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-153472
Thanks, I have added the below code:
<div class="row">
<div class="col-sm-12">
<div style="display:none ;">[wpv-post-taxonomy type='location' format='name' value='[wpv-post-taxonomy type='location' item='$current_page'][/types]']</div>
</div>
<div class="row">
<div class="col-sm-12">
<div style="display:none ;">[wpv-post-taxonomy type='building' format='name' value='[wpv-post-taxonomy type='building' item='$current_page'][/types]']</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div style="display:none ;">[cred_field field='building-details' value='[types field='building-details' item='$current_page'][/types]']</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div style="display:none ;">[cred_field field='room-name-number' value='[types field='room-name-number' item='$current_page'][/types]']</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div style="display:none ;">[cred_field field='space-id' value='[types field='space-id' item='$current_page'][/types]']</div>
</div>
</div>
But the only one showing in the email notification is the room-name-number field. hidden link
I removed display none to see if they are showing in the form hidden link
The taxonomy terms are showing on the form but with '] on the end
The other fields are displaying 'There is a problem with building-details field. Please check CRED form.' but they are in the same format as the 'room-name-number' that is working correctly
It is expected. Only the 'space-id' is available on the custom post type for inquiries, the other fields do not. Either add the other fields to the custom post type or use generic fields instead.
Can you tell me which one you would like to do?
Remember that custom fields will be stored, each inquiry will also have the "space-id". You will have to decide if the other fields should also be stored within the inquiry or not.
Okay I tried to add the other fields on the Inquiry 'Space form entries' post type but getting this error message 'Warning: field slug already used' because they are already fields of the 'Available space' post type
I checked the room-name-number field slug and its the same on both post types, so unsure why I'm not able to save the other fields
We cannot have two custom fields with the same slug, but we can choose from previously created fields. Check this screenshot. Check this screenshot hidden link
That worked!! thanks! those fields are not showing in the email notification 🙂
Just the taxonomy fields now that are still missing, is the below code correct or missing something?
div class="row">
<div class="col-sm-12">
<div style="display:none ;">[wpv-post-taxonomy type='location' format='name' value='[wpv-post-taxonomy type='location' item='$current_page'][/types]']</div>
</div>
<div class="row">
<div class="col-sm-12">
<div style="display:none ;">[wpv-post-taxonomy type='building' format='name' value='[wpv-post-taxonomy type='building' item='$current_page'][/types]']</div>
</div>
</div>
This code will not actually pass any information to the form processing as it does not use [cred_field]. The code will just display both taxonomies (location, building) for the current post. It should go inside an [cred_field] in the "value" attribute.
As location and building are taxonomies, you will have to attach these taxonomies to the "Space enquiry form" custom post type.
I did not test this use case previously(passing taxonomy terms through a form), and I am not sure if the following code will work:
[cred_field field='location' force_type='taxonomy' value='[wpv-post-taxonomy type='location' item='$current_page'][/types]']
[cred_field field='building' force_type='taxonomy' value='[wpv-post-taxonomy type='building' item='$current_page'][/types]']
If it does not work, we can build custom code and hook into the form to set the taxonomies our selves. Check a slightly similar example using generic fields here https://toolset.com/forums/topic/passing-default-value-to-taxonomy-throws-error-but-works/
And forms API here https://toolset.com/documentation/programmer-reference/cred-api/