<p>The Craft Form Macro file is in the Craft package.</p>
<p>The <code>forms.html</code> file is the <a href="https://github.com/craftcms/cms/blob/794f21422068e92631b5798076ef62780ea988f1/src/templates/_includes/forms.html" rel="nofollow noreferrer">macro file</a>, and that file loads several other templates depending on which form macro is being used.</p>
<pre><code>vendor/craftcms/cms/src/templates/_includes/forms.html
</code></pre>
<p>You can see the individual files in <a href="https://github.com/craftcms/cms/tree/3.6.16/src/templates/_includes/forms" rel="nofollow noreferrer">this directory</a>:</p>
<pre><code>vendor/craftcms/cms/src/templates/_includes/forms/
</code></pre>
<p>Unfortunately, there is no documentation on how these work. I'd recommend to start by getting familiar with <a href="https://twig.symfony.com/doc/2.x/tags/macro.html" rel="nofollow noreferrer">Twig macros</a>, and then you can look through the <code>vendor/craftcms/cms/src/templates</code> folder, various plugin template folders, or the Sprout Reports example files to see several examples of how macros are being used.</p>

CC BY-SA 4.0
2021-06-03T18:04:03.053Z
2021-06-03T18:04:03.053Z
Ben Parizek
<p>I'm using Sprout Reports, which makes this reference:</p>
<blockquote>
<p>Use the Form Macros supported by the Craft CP to keep consistent with
the Craft UI. Sprout Reports will import the Craft CP Form Macros.
Your Settings Template can look like this where the imported forms
variable includes all Craft form macros defined in
<strong>craft/app/templates/_includes/forms.html</strong></p>
</blockquote>
<p>Where in the world do I find this information? And is it documented anywhere?</p>
<p>My inquiry was prompted by needing to know how to make a form field selection required.</p>

CC BY-SA 4.0
2021-06-03T18:07:45.840Z
Here's an example of Craft using a macro to make a Text field required in the section settings. The select field would be handled the same way – adding the `required: true,` attribute to the `selectField` macro.
Ben Parizek
<form><macro><plugin-sproutreports><sprout>
Where in the world are CP form macros stored?
# Where in the world are CP form macros stored?

(Asked by: username_0 on 2021-06-03)

I'm using Sprout Reports, which makes this reference:

> Use the Form Macros supported by the Craft CP to keep consistent with
> the Craft UI. Sprout Reports will import the Craft CP Form Macros.
> Your Settings Template can look like this where the imported forms
> variable includes all Craft form macros defined in
> **craft/app/templates/\_includes/forms.html**

Where in the world do I find this information? And is it documented anywhere?

My inquiry was prompted by needing to know how to make a form field selection required.

**Tags:** form, macro, plugin-sproutreports, sprout
> **Comments:**
> **username_1**: Here's an example of Craft using a macro to make a Text field required in the section settings. The select field would be handled the same way – adding the `required: true,` attribute to the `selectField` macro.  

---

## 1 answers

### Answer by username_1 on 2021-06-03. Score: 3 | Accepted answer

The Craft Form Macro file is in the Craft package.
The forms.html file is the macro file, and that file loads several other templates depending on which form macro is being used.
vendor/craftcms/cms/src/templates/_includes/forms.html

You can see the individual files in this directory:
vendor/craftcms/cms/src/templates/_includes/forms/

Unfortunately, there is no documentation on how these work. I'd recommend to start by getting familiar with Twig macros, and then you can look through the vendor/craftcms/cms/src/templates folder, various plugin template folders, or the Sprout Reports example files to see several examples of how macros are being used.


---

