Skip Navigation

[Resolved] Specific contact form

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

Problem: I created a custom type named 'member' with a field named 'mail'. I want to display after the member content (of each member) a form with subject, email of the sender and body inputs. When submitting this form an email will be sent to the member using his e-mail address (field 'mail').

Solution:
- Create a new post type called "Guest Messages" or something similar. Every time someone submits the form on the front-end of the site, a new post will be created in this post type.
- Create a new custom field group that contains all the fields you want to display in the form - subject, sender email, and message. Assign this field group to the Guest Messages post type.
- Create a CRED form that creates new Guest Messages posts. Auto-generate the form code, then insert a hidden generic field. Set the value of that hidden field to be the "mail" field value of the current Member, like this:

<div style="display:none;">[cred_generic_field field='member-email' type='email' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field name='wpcf-mail' id='$current_page']"
}
[/cred_generic_field]</div>

- Insert any other information you want the email to include using Types and Views shortcodes.
- In the CRED notification builder, you select the generic hidden field "member-email" to be used as the "To:" destination email address. You may have to submit the form once on the front-end of the site to see your hidden field appear in the options here.
- Insert this CRED form in the Content Template or Template Layout assigned to the Members post type using the CRED forms shortcodes.

Relevant Documentation:
https://toolset.com/documentation/user-guides/#cred-topics
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/user-guides/automated-email-notifications-with-cred/

This support ticket is created 6 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.

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 21 replies, has 2 voices.

Last updated by thibaultS 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#860345

Tell us what you are trying to do?
I created a custom type named 'member' with a field named 'mail'. I want to display after the member content (of each member) a form with subject, email of the sender and body inputs. When submitting this form an email will be sent to the member using his e-mail address (field 'mail'). How can i do that ? which component do i need to use ?

What is the link to your site?
hidden link

#860759

You'll use CRED ( soon to be called Toolset Forms ) to accomplish this. Here's how I would set this up:
- Create a new post type called "Guest Messages" or something similar. Every time someone submits the form on the front-end of the site, a new post will be created in this post type.
- Create a new custom field group that contains all the fields you want to display in the form - subject, sender email, and message. Assign this field group to the Guest Messages post type.
- Create a CRED form that creates new Guest Messages posts. Auto-generate the form code, then insert a hidden generic field. Set the value of that hidden field to be the "mail" field value of the current Member, like this:

<div style="display:none;">[cred_generic_field field='member-email' type='email' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field name='wpcf-mail' id='$current_page']"
}
[/cred_generic_field]</div>

- Insert any other information you want the email to include using Types and Views shortcodes.
- In the CRED notification builder, you select the generic hidden field "member-email" to be used as the "To:" destination email address. You may have to submit the form once on the front-end of the site to see your hidden field appear in the options here.
- Insert this CRED form in the Content Template or Template Layout assigned to the Members post type using the CRED forms shortcodes.

Let me know if you have questions about this. Here are some reference materials:
https://toolset.com/documentation/user-guides/#cred-topics
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/user-guides/automated-email-notifications-with-cred/

#865157
Capture du 2018-05-09 09-28-19.png

So i've done what you said :
- The custom post type was created with the required fields
- The CRED form was created with fields and captcha
- The notification was created with the use of the hidden field

The content submitted is stored, but no e-mail sent.

I check if mail are working on my server with the send test e-mail button (bottom of "edit notification" in CRED form), it works (no value from fields but the rest is ok).

Can you help me fix this error ?

The code of my CRED form :

[credform class='cred-form cred-keep-original']
	<h1>[wpml-string context="custom-form" name="send_message"]Lui envoyer un message[/wpml-string]</h1>

	[cred_field field='form_messages' value='' class='alert alert-warning']

    <div style="display:none;">[cred_field field='receiver' post='guest-message' class='' urlparam='' value="[wpv-post-field name='wpcf-firstname' id='$current_page'] [wpv-post-field name='wpcf-name' id='$current_page']"]
    [cred_generic_field field='member-email' type='email' class='' urlparam='']
    {
    "required":0,
    "validate_format":0,
    "persist":1,
    "default":"[wpv-post-field name='wpcf-mail' id='$current_page']",
    }
    [/cred_generic_field]</div>

	<div class="form-group">
		<label>[wpml-string context="custom-form" name="sender"]Expéditeur[/wpml-string]</label>
		[cred_field field='sender' post='guest-message' value='' urlparam='' class='form-control' output='bootstrap']
	</div>

	<div class="form-group">
		<label>[wpml-string context="custom-form" name="subject"]Sujet[/wpml-string]</label>
		[cred_field field='post_title' post='guest-message' value='' urlparam='' class='form-control' output='bootstrap']
	</div>

	<div class="form-group">
		<label>[wpml-string context="custom-form" name="message"]Message[/wpml-string]</label>
		[cred_field field='post_content' post='guest-message' value='' urlparam='' output='bootstrap']
	</div>

	[cred_field field='recaptcha' value='' urlparam='' class='form-control' output='bootstrap']
	[cred_field field='form_submit' value='Envoi' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

[/credform]

The code of the notification :

<p>[types field='sender'][/types] send you this message :</p>
<p>[wpv-post-body view_template="None"]</p>
#867581

It would appear that the generic field information is not being set. Please add some debugging code just before the hidden div:

Current post ID: [wpv-post-id id='$current_page']<br />
Mail field: [wpv-post-field name='wpcf-mail' id='$current_page']<br />
... the hidden div code begins here...

The current post ID should match the ID of the post where the wpcf-mail custom field is found. The mail field value should be accurate. Let me know the results.

#868175

The result is correct

Current post ID: 149
Mail field: juergen.sarbach@...

but no mail

#868284

Is your site using an SMTP mail plugin? Most SMTP plugins modify mail headers in a way that CRED cannot override. As a quick test, please activate a default theme like Twenty Seventeen, then deactivate all plugins except Toolset plugins, and test again. If the problem is still not resolved, please toggle all the email notification editors open in this CRED form editor, and take a full screenshot or a series of screenshots showing all the configurations here for me to review.

#868597
cred_form-fullpage.png

I don't use SMTP plugin (only toolset, wpml and db sync). nevertheless i desactived wpml and db sync. sitch to twentyseventeen.

Same result : i.e message stored in data base but no mail. So i send you the screenshoot.

Regards

#868605

Can you open the Email Notification and send me a screenshot of that too? It's toggled closed in this screenshot.

#868606
cred_notification-fullpage.png

Sorry, forgot this one

#868639

Okay I don't see anything obviously wrong here. Let's try a few more troubleshooting steps, and if these don't work I will need to make a clone of your site so I can run tests locally.
- Check the checkbox "Envoyer une notification a une adresse email specifique", and send to a different email address, preferably on a different domain than the Member's email address.
- Check the spam email folders to see if the emails are being blocked by a filter

Let me know if the email is sent to either address.

#868682

OK,

If i check the checkbox and specify an address it send the email.

#868703

It sends the email to both email addresses, or only the address specified in wp-admin?

What if you copy the Member's email address into the specified address field (send to the same email address twice)?

#868706

Sorry i have unchecked the previous checkbox.

So with both checkboxes checked, only the e-mail for the static e-mail was sent.

Regards

#868767

Okay at this point I think I need to create a clone of your website so I can run some additional tests. I can install the Duplicator plugin to make that clone. If you approve, please provide login credentials here in the private reply fields.

#869219

Okay, I inspected the form on the front-end of the site, and I can see that the generic field was not in the page markup. So I looked at the generic field shortcode and it turns out the trailing comma at the end of the default value definition was causing a problem:

    [cred_generic_field field='member-email' type='email' class='' urlparam='']
    {
    "required":0,
    "validate_format":0,
    "persist":1,
    "default":"[wpv-post-field name='wpcf-mail' id='$current_page']",
    }
    [/cred_generic_field]

I deleted that trailing comma and now I see the form element appear. Can you test once more and confirm the message is sent to the Member's email?