Skip Navigation

[Resolved] Form tool suggestion

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to create a contact form for my site, but I do not necessarily want to create posts with this Form. I would prefer to use it strictly for sending email notifications.

Solution: Toolset Forms can send email notifications, but those forms will always create or edit some post. There is no easy workaround to prevent the creation of posts, but you could create a custom cron script that automatically deletes those posts at regular intervals if you do not want to keep them stored in your database.

This support ticket is created 2 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 7 replies, has 3 voices.

Last updated by kaanA 2 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#2134045

I'm trying to create a directory for medical clinics where clinics will have a profile page.

A visitors can request consultation from clinics by filling a request consultation form.

I would like to create 1 form and embed it to Custom Post Type clinic.
I want that this form collects the clinic ID (custom field of a clinic) dynamically from the page where it is being displayed.

I think I can create a new post type called consultation requests and achieve this BUT I do not want to create this request and do not want to save consultation requests in wordpress database.

So my question can I achieve this using Toolset or could you suggest a form tool which would allow me to achieve this?

#2134507

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Toolset Forms always publish (or edit) posts, so a request form will aways generate a request post.

Forms can send notifications, so the request post itself is essentially disposable, and you could create a cron job to periodically delete all request posts.

You could use a contact form plugin that doesn't save submissions instead, perhaps, but I don't know how feasible it is to dynamically include the clinic ID in such a case.

You can do that with a Toolset Form, by adding a field for the clinic ID to the request post type and including it in the Form, and then in the settings for that field, provide a default value for the field using a shortcode that outputs the field value from the clinic post where the form is being displayed (which is the context for the form, so any shortcode used in a form such as wpv-post-field will take its value from the post where the form is inserted).

#2134725

Thank you Nigel.
Super useful and detailed answer.
One final question is there a contact form (wordpress based) that you are aware of which is tightly integrated with Toolset so I can check that tool first.

#2134739

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

There aren't any that are integrated with Toolset, as Toolset already has its own solution for forms.

I'd check the popular contact form plugins and see if there is a way to pass the clinic ID, e.g. via a shortcode, though if they are not retaining the submissions as posts the most they would be able to do is include it in the message somehow.

#2134795

Thank you Nigel.
I followed your suggestion and used Toolset form. (to create custom post types named ConsultationRequests)

Here are the issues that I faced;
After a form submission, a new consultation request post is created and I have no control of the post's name. Currently they are named as "CRED Auto Draft 1ba98e1a2f326331c80bff5a19367abc" , can I change this?
I used the shortcode in a hiddenform it works but then field value is not part of the submission and not visible in that Consultation Request.
I created a clinicID custom field under the Consultation Request post type but then I couldn't figure out to have the field in the form in a hidden format. (besides using CSS maybe)

#2134823

Hi Nigel,

I followed your instructions.
I created a custom post type called "Consultation Request" which also has a custom field called "ClinicID" .
I then created Toolset form but faced some isues.

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
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.

Could you please comment?

#2135047

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
  }
}
#2135589

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.