1- When a new Consultation Request is submitted I have no control how the post will named. Currently new posts are named as CRED Auto Draft 1ba98e1a2f326331c80bff5a19367abc . Can I change this
Yes, one simple way is to insert the post title field in the Form and set its default value using simple text or a combination of text and shortcodes. If you do not want to display this field to the end User, you can hide it with CSS. If you would prefer to set the post title programmatically without a title field in the Form, you can use our Forms API and a small custom code snippet like this:
// automate Consultation Request post titles created by Forms
// https://toolset.com/forums/topic/form-tool-suggestion/
add_action('cred_submit_complete', 'tssupp_set_cr_title',10,2);
function tssupp_set_cr_title($post_id, $form_data)
{
$forms = array(123, 456);
$post_title = "Consultation Request #" . $post_id;
// you probably should not edit anything below this line
// if a specific form
if ( in_array( $form_data['id'], $forms ) )
{
$args = array(
'ID' => $post_id,
'post_title' => $post_title
);
wp_update_post( $args );
}
}
Replace 123, 456 in this code with the numeric ID of the Form that creates Consultation Request posts. If there is more than one Form and you would like to add the title in all these Forms, you can include multiple Form IDs separated by commas. The post title is set here:
$post_title = "Consultation Request #" . $post_id;
Currently the title is set with some simple text followed by the post ID of the new Consultation Request post. You can adjust this using your own custom code.
2- I can populate the clinicID based on where the form is displayed but at the same time I do not that this field is visible to visitor. If I create a hidden field then this is not being used when Consultation Request is created. If I use the custom field called ClinicID in the form then the field is visible to the visitor.)
The simplest solution is to use the custom field and hide it with CSS, like you mentioned. Another solution is to place the ClinicID information in the default value of a hidden generic field in the Form. Generic fields are available in the Form builder; you will choose the generic field type "hidden" when you insert a generic field. If you set the slug of your generic field appropriately, this will store the ClinicID value in a Types ClinicID custom field in the Consultation Request post. All fields created in Types have a wpcf- slug prefix in the database, so the generic field slug should include the same wpcf- prefix to store the information in the correct custom field.
For example, if the slug of your ClinicID Types custom field is clinic-id, then you would set the slug of the generic hidden field to be wpcf-clinic-id. If the slug of your ClinicID Types custom field is clinicid, then you would set the slug of the generic hidden field to be wpcf-clinicid.
Let us assume the Clinic ID is just the ID of the Clinic post where the Form is displayed. Let us assume the Consultation Request post contains a custom field with the slug clinic-id. You want to store the ID of the Clinic post inside the clinic-id custom field in the Consultation Request post when the Form is submitted. In the "expert mode" Form builder, you can insert the generic field and customize the shortcode like this:
[cred_generic_field type='hidden' field='wpcf-clinic-id']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-id item='$current_page']"
}
[/cred_generic_field]
This will automatically set the custom field value to match the ID of the Clinic Post where the form was submitted.
If you want to access the values submitted in generic fields some other way, you can use the PHP APIs like cred_submit_complete or cred_save_data to access those generic field values in the $_POST superglobal. If the generic field has the slug "generic-hidden-1", you would be able to get the value of that hidden field like so:
// generic field demonstration
// https://toolset.com/forums/topic/form-tool-suggestion/
add_action('cred_submit_complete', 'tssupp_generic_demo',10,2);
function tssupp_generic_demo($post_id, $form_data)
{
$forms = array(123);
// if a specific form
if ( in_array( $form_data['id'], $forms ) )
{
$hidden = $_POST['generic-hidden-1'];
// now $hidden contains the value of the generic hidden field
}
}