Skip Navigation

[Resolved] CRED Form won't fetch the email from the displayed result to send notification

This support ticket is created 5 years, 9 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by Shane 5 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1188115

Hi,

In continuation for https://toolset.com/forums/topic/add-contact-form-that-sends-email-to-custom-field-email-of-the-post/ I have to open a new ticket because I am having trouble to get this to work.

I explain you the situation:

we have a classified page, where there are thousand of professional members. People can contact them through their directory profiles. So, any user can search for the professional member he or she wants, and then can contact him or her by giving an email and a message in the post page of that member.

The classified listing directory page is here: hidden link

And, for instance, you can access to a test member page I have created here: hidden link

The toolset template used for the page is based on divi. It has a fullwidth module with this code of the map:

{!{wpv-map-render map_id="map-10" map_width="100%" map_height="260px" map_type_control="off" marker_icon="//sofrocay.com/wp-content/uploads/2018/08/sofrocay-logo.png" style_json="<em><u>hidden link</u></em>"}!}{!{/wpv-map-render}!}
{!{wpv-map-marker map_id='map-10' marker_id='marker-8' marker_field='wpcf-direccion_completa'}!}<h1 class="membretitle" style="padding-top:0px!important;">{!{types field="nombre"}!}{!{/types}!}</h1><p class="textmembre">{!{types field='direccion'}!}{!{/types}!}<br>{!{types field='codigo_postal'}!}{!{/types}!} {!{types field='region'}!}{!{/types}!} {!{types field='poblacion'}!}{!{/types}!}- {!{types field='pais'}!}{!{/types}!}<br>{!{wpv-conditional if="( $(wpcf-movil) ne '' ) OR ( $(wpcf-telefono) ne '' )"}!}tel : {!{/wpv-conditional}!}{!{types field="telefono"}!}{!{/types}!}{!{wpv-conditional if="( $(wpcf-movil) ne '' )"}!} / {!{/wpv-conditional}!}{!{types field="movil"}!}{!{/types}!}</p>{!{/wpv-map-marker}!}

Then it has a two column layout with this at the left:

[cred_form form="annuaire-form"]

And this at the right:

<h3>{!{types field='nombre'}!}{!{/types}!}</h3>
<p><strong>{!{types field='direccion'}!}{!{/types}!}<br>{!{types field='codigo_postal'}!}{!{/types}!} {!{types field='region'}!}{!{/types}!} {!{types field='poblacion'}!}{!{/types}!}- {!{types field='pais'}!}{!{/types}!}</strong></p>
<p>{!{wpv-conditional if="( $(wpcf-telefono) ne '' ) OR ( $(wpcf-movil) ne '' )"}!}<strong>Tel :</strong> {!{types field='telefono'}!}{!{/types}!} / {!{types field='movil'}!}{!{/types}!}{!{/wpv-conditional}!}{!{wpv-conditional if="( $(wpcf-email) ne '' )"}!}<br><strong>e-mail : </strong>{!{types field='email' output='raw'}!}{!{/types}!}{!{/wpv-conditional}!}</p>

As you can see, the CRED form shown in every professional profile page of the directory, is [cred_form form="annuaire-form"]

When you go to the CRED form edit page you find this content

[credform]
<div class="form-group"style="display:none;">
[cred_generic_field field="hidden-email" type="hidden" class=""]
 {
  "required":0,
  "validate_format":0,
  "default":"[types field='email' output='raw'][/types]",
  "persist" : 1,
 }
[/cred_generic_field]
    </div>
    <div class="form-group">
        <label>Votre e-mail</label>
        [cred_field field="courriel" force_type="field" class="form-control"  placeholder="Votre e-mail" output="bootstrap"]
    </div>
    <div class="form-group">
        <label>Vos nom et prénom</label>
        [cred_field field="nom" force_type="field" class="form-control"  placeholder="Vos nom et prénom" output="bootstrap"]
    </div>
    <div class="form-group">
        <label>Votre message</label>
        [cred_field field="demande" force_type="field" class="form-control" placeholder="Votre message" output="bootstrap"]
    </div>
    [cred_field field="recaptcha" class="form-control" output="bootstrap"]
    [cred_field field="form_submit" output="bootstrap" value="Envoyer" class="btn btn-primary btn-lg"]
[/credform]

Also, this CRED Form, generates two emails. One for the sender:

[types field='nom'][/types],

Votre message a bien été transmis à [types field='nombredestinatario'][/types]

[types field='nombredestinatario'][/types] vous répondra dans les meilleurs délais.

and one for the receiver

[types field='nombredestinatario'][/types],

Vous avez reçu un message depuis l'annuaire de sofrocay.com de la part de :

[types field='nom'][/types] - [types field='courriel' output='raw'][/types]

<strong>[types field='demande' output='raw'][/types]</strong>

Our first approach was to obtain the mail of the professional member from an url param:

<em><u>hidden link</u></em>

, but we have the problem that when a user access directly to the member's page without the url param, the form, obviously, won't work:

<em><u>hidden link</u></em>

That's why we needed another solution to fetch the email of the current displayed post into the form.

Your first approach was to add a hidden-field like this:

[cred_generic_field field="hidden-email" type="hidden" class=""]
 {
  "required":0,
  "validate_format":0,
  "default":"[types field='email' output='raw'][/types]",
  "persist" : 1,
 }
[/cred_generic_field]

Note that the type field email of the custom post is the email we want to fetch.

But adding this, I can confirm that I cannot select the field "hidden-email" as notification recipient. You said in your last post that by saving the form and refreshing it, I would be able to select it on the dropdown selector, but no success found with this.

I have changed this

[cred_generic_field field="hidden-email" type="hidden" class=""]

to this

[cred_generic_field field="hidden-email" type="email" class=""]

and now I can select the email from the dropdown recipient notification selector, but when I fill the form without the urlparams, the form won't send the email to the custom field email of that post.

I have recorded a screen video specifically for you to show you the problem with more detail.

Please, take a look on it: hidden link

I hope I have been clear for you,

thank you,

Mario

#1188218

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mario,

Thank you for contacting our support forum.

Would you mind providing me with admin access to the website so that I can check on this issue for you ?

Thanks,
Shane

#1189173

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mario,

The correct code for the generic field should be

 [cred_generic_field type='hidden-email' field='email' class=""]
 {
  "required":0,
  "validate_format":0,
  "default":"[types field='email' output='raw'][/types]",
  "persist" : 1
 }
[/cred_generic_field]

You can now setup your notification for this field.

Thanks,
Shane

#1189204
Captura de pantalla 2019-01-22 a las 20.42.53.png

Thank you Shane,

unfortunately, being now the code as you suggested:

[credform]

	<div class="form-group" style='display:none;'>
     [cred_generic_field type='hidden-email' field='email' class=""]
 {
  "required":0,
  "validate_format":0,
  "default":"[types field='email' output='raw'][/types]",
  "persist" : 1
 }
[/cred_generic_field]
		<label>toEmail</label>
		[cred_field field="toemail" force_type="field" class="form-control" output="bootstrap" urlparam="toEmail"]
      [cred_field field='nombredestinatario' force_type='field' class='form-control' output='bootstrap' urlparam='nomdestinatario']
      [cred_field field='telefonodestinatario' force_type='field' class='form-control' output='bootstrap' urlparam='telefonodestinatario']
      [cred_field field='movildestinatario' force_type='field' class='form-control' output='bootstrap' urlparam='movildestinatario']
	</div>
	<div class="form-group">
		<label>Votre e-mail</label>
		[cred_field field="courriel" force_type="field" class="form-control"  placeholder="Votre e-mail" output="bootstrap"]
	</div>
	<div class="form-group">
		<label>Vos nom et prénom</label>
		[cred_field field="nom" force_type="field" class="form-control"  placeholder="Vos nom et prénom" output="bootstrap"]
	</div>
	<div class="form-group">
		<label>Votre message</label>
		[cred_field field="demande" force_type="field" class="form-control" placeholder="Votre message" output="bootstrap"]
	</div>
	[cred_field field="recaptcha" class="form-control" output="bootstrap"]
	[cred_field field="form_submit" output="bootstrap" value="Envoyer" class="btn btn-primary btn-lg"]
[/credform]

the notification couldn't be set with the "email" field as the image shows.

What can I do to make it work?

Thank you,

Mario

#1189211

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mario,

Change the field type here from type='hidden-email' to type='email'

This should cause it to start working now.

Thanks,
Shane

#1189607

Thank you Shane,

now it works after your suggestion:

[credform]
<div class="form-group" style='display:none;'>
[cred_generic_field type='email' field='email' class=""]
 {
  "required":0,
  "validate_format":0,
  "default":"[types field='email' output='raw'][/types]",
  "persist" : 1
 }
[/cred_generic_field]
[cred_field field='nombredestinatario' force_type='field' class='form-control' output='bootstrap' urlparam='nomdestinatario']
</div>
	<div class="form-group">
		<label>Votre e-mail</label>
		[cred_field field="courriel" force_type="field" class="form-control"  placeholder="Votre e-mail" output="bootstrap"]
	</div>
	<div class="form-group">
		<label>Vos nom et prénom</label>
		[cred_field field="nom" force_type="field" class="form-control"  placeholder="Vos nom et prénom" output="bootstrap"]
	</div>
	<div class="form-group">
		<label>Votre message</label>
		[cred_field field="demande" force_type="field" class="form-control" placeholder="Votre message" output="bootstrap"]
	</div>
	[cred_field field="recaptcha" class="form-control" output="bootstrap"]
	[cred_field field="form_submit" output="bootstrap" value="Envoyer" class="btn btn-primary btn-lg"]
[/credform]

I have removed the toEmail param. We have to do the same with the "nombredestinatario" field, that is the name of the member (like in hidden link, "Test Ecole") . As you can see, I fetched it from the "nomdestinatario" url param and filled in the notifications, but when this param is not in the URL, the name of the recipient will not be shown in the notifications.

We need, as done with the email field, to fetch it from the current post shown. Its slug is "nombre"

As happened with the email field, as the CRED form is a simple shortcode, I cannot add the field "nombre" inside the form, because it won't render the name.

Please, thanks for your last solution, but I would need also to render the name of the post inside the notifications as well, without passing it through an URL param,

How could you approach to this?

Thank you,

Mario

#1189738

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mario,

The correct way would be like this.
[cred_field field='nombredestinatario' force_type='field' class='form-control' output='bootstrap' value="[types field='nombre' output='raw'][/types]"]

Please let me know if this helps.
Thanks,
Shane

#1189761
Captura de pantalla 2019-01-23 a las 15.42.44.png

Thank you Shane,

your code solved this problem. However I see that the toemail field is not being saved in the DB, even though that "persist" : 1 is set.

You can go to this post submitted with the form to see that now the nombredestinatario is saved, but toemail is not saved: hidden link

Why this:

[cred_generic_field type='email' field='toemail' class=""]
 {
  "required":0,
  "validate_format":0,
  "default":"[types field='email' output='raw'][/types]",
  "persist" : 1
 }
[/cred_generic_field]

is not saving the field toemail inside the post that generates in the DB? You can see it in the attached image

Thank you

Mario

#1189818

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mario,

Since this is a types custom field it is saving to, you simply need to change the field attribute to "field=wpcf-toemail"

Thanks,
Shane