Uniform - what do I change to use a snippet?

I have Uniform up and running, but want to use a snippet. I have read this, but still don’t understand what I need to change, exactly, in my actions/email.php file to point to my snippet rather than use the default. Obviously, I’m new at this.

Any help would be appreciated. Thanks!

See this post: Using Uniform contact form in snippet not in template

Sorry - wasn’t clear. I want to use a snippet for my email template. (I already have the form itself in a snippet.) I have created an email template snippet, but I do not know what to change in the email action to point to that snippet instead of using the default email template.

I’m afraid I don’t quite understand what you mean and how it relates to the issue you linked to. Could you please post your code, maybe?

The thread I linked to discusses including the value from “_from” field in the email that is sent after the form is submitted. To do this, you need to first create an email template snippet and, next, modify the actions/email.php

My problem is I do not know what to change in actions/email.php to tell Uniform to use the new custom email snippet for its template rather than the default template.

This link explains what should happen, but I am afraid I do not know what code to change to make it work.

I don’t have any code to post because my issues is I do not know what code to change.

@mzur

I see.

What you have to do:

  1. Create an email template snippet like one of the examples in the repo.
  2. In the actions array, add the name of the snippet:
$form = uniform('contact-form',[
    'required' => [
        '_from' => 'email'
    ],
    'actions' => [
        [
            '_action' => 'email',
            'to'      => (string) $page->email(),
            'sender'  => 'info@my-domain.tld',
            'subject' => $site->title()->html() . ' - message from the contact form',
            'snippet' => 'name_of_snippet'
        ]
    ]
]);

Edited:

Just had a simple error in the way I was calling the snippet. It’s properly referenced now. But I’m getting another error. I’m using a snippet from the repo: email-table.php

I’m getting an undefined error on the $data variable:

foreach ($data as $field => $value):

Whoops \ Exception \ ErrorException (E_NOTICE)
Undefined variable: data

Update:

So it turns out that line should be:

foreach ($form as $field => $value):

This seemed like a logical fix, because in uniform/actions/email we’re using:

foreach ($form as $key => $value)

Just as a side note: Please note that the syntax above refers to the old Uniform plugin. In the new version, the options are still the same including the way to reference a snippet, though. See the documentation.