Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Help adding Contact form with multiple contact

first-time

Solved by pamtbaau View solution

Started by Raj 5 years ago · 7 replies · 1017 views
5 years ago

I have an issue adding a second contact form to the same page
I tried to follow this: https://learn.getgrav.org/17/forms/forms

YAML
forms:
    contact-form:
        fields:
            ...
        buttons:
            ...
        process:
            ...

    newsletter-form:
        fields:
            ...
        buttons:
            ...
        process:

but without success, maybe very simple, missing something

was trying to set up something like this:
user can toggle the form or option to select like user1 or user2
form1 goes recipient or user 1
form2 goes recipient or user 2

hope someone can put me in the right direction Thank you

5 years ago

Is anyone having similar issues?

5 years ago

What do you have so far? What exactly is not working (form sent to wrong recipient, wrong form displayed, ...)? What do you have in your forms' process configs?

5 years ago

the signal form works fine, I was trying to set up multiple selection options
example:
user can toggle the form selection or option:
select Info
email should go to recipient [email protected]

If form selection or option:
select sales
email should go to recipient [email protected]

When I test, it goes to default email on the system, I am able to add another recipient, but that's not what I want. I want info to go to [email protected] and sales go to [email protected]

Thank you

5 years ago

If I understand what you're saying, you have a select with two options whom to contact. Depending on selected option, email should be sent to different recipient. If so, just use <option value="[email protected]">Sales</option>

And in process field use something like

YAML
process:
    - email:
        to: "{{ form.value.contact_email|e }}"

It's in the docs

Can't give more detailed answer without knowing how your select field is set up

5 years ago

I had looked at document, but was little confused, I think I was mixing something, but I will test and update if this works out Thank you

Dynamic email attribute

If you want for example to set the email.from field from a Form input, you can get its content and use it in this way:

from: "{{ form.value.email|e }}"

In this case, we get the field "email" from the form, and use it for the "from" attribute. This way the site owner will receive an email and will be able to directly reply to the email entered in the form.

5 years ago Solution

@ramraj, To save you some time, you might want to give the following form definition a try:

YAML
---
form:
  name: contact
  fields:
    topic:
      type: select
      options:
        '[email protected]': General information
        '[email protected]': Sales information
  buttons:
    submit:
      type: submit
      value: Submit
  process:
    email:
      subject: 'Site Contact Form'
      body: "{% include 'forms/data.html.twig' %}"
      to: '{{ form.value.topic|e }}'
---
👍 1
last edited 09/08/21 by pamtbaau
5 years ago

@Karmalakas @pamtbaau
it works Thank you very much for your help

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1144 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 63 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 138 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 114 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 132 7 months ago