<p>Matrix fields can only be used as custom fields, on an element.</p>

<p>If you really want to use them, you would need to create a custom Element Type (see the resources at the bottom of <a href="http://buildwithcraft.com/docs/plugins/working-with-elements" rel="nofollow">http://buildwithcraft.com/docs/plugins/working-with-elements</a>), and then create a Matrix field that is associated with your element type’s field layout.</p>

CC BY-SA 4.0
2020-02-12T14:26:02.820Z
Is it applied for craftcms 3.x as well or we can add directly now without creating the element type.
inrsaurabh
CC BY-SA 4.0
2020-02-12T23:53:33.820Z
@inrsaurabh Same answer applies to Craft 3
Brandon Kelly
CC BY-SA 3.0
2014-09-23T18:28:23.543Z
2014-09-23T18:28:23.543Z
Brandon Kelly
<p>I'm just starting to explore the whole power of Craft and I'm really satisfied with its possibilities so far.</p>

<p>But I can't get one thing done, so here's my question:</p>

<p>Is it possible to use matrix fields in my very own plugins? I already finished a form with several fields just as text inputs and stuff but I really need to extend this thing with a matrix field.</p>

<p>Am I just blind and it's documented anywhere or is it a more complicated task than I can imagine at this point?</p>

<p>Thanks for your help.</p>

<p>Jonas</p>

CC BY-SA 3.0
2014-09-23T13:49:08.587Z
One thing you might want to consider, if all your plugin does is collects input, is to use something like Guest Entries/frontend edit form to do the same. If you do need to do some custom processing on the collected data, you might hook into any of the available events, like onSaveEntry.
Fred Carlsen
CC BY-SA 3.0
2014-09-23T14:07:40.067Z
Don't know how you plan to store your data but you might want to take a look at the [Element API](http://buildwithcraft.com/docs/plugins/working-with-elements#creating-new-element-types) to create your own element and use it with any available fields (just like Entries, Assets, etc...)
Benjamin David
CC BY-SA 3.0
2014-09-24T09:31:29.623Z
Thanks guys, I will try Brandons solution which seems to be kinda the same Benjamin offered?! Anyway, thank you.
LikeAJohny
<matrix><field>
Matrix fields within a plugin?
# Matrix fields within a plugin?

(Asked by: username_0 on 2014-09-23)

I'm just starting to explore the whole power of Craft and I'm really satisfied with its possibilities so far.

But I can't get one thing done, so here's my question:

Is it possible to use matrix fields in my very own plugins? I already finished a form with several fields just as text inputs and stuff but I really need to extend this thing with a matrix field.

Am I just blind and it's documented anywhere or is it a more complicated task than I can imagine at this point?

Thanks for your help.

Jonas

**Tags:** matrix, field
> **Comments:**
> **username_1**: One thing you might want to consider, if all your plugin does is collects input, is to use something like Guest Entries/frontend edit form to do the same. If you do need to do some custom processing on the collected data, you might hook into any of the available events, like onSaveEntry.  
> **username_2**: Don't know how you plan to store your data but you might want to take a look at the [Element API](http://buildwithcraft.com/docs/plugins/working-with-elements#creating-new-element-types) to create your own element and use it with any available fields (just like Entries, Assets, etc...)  
> **username_0**: Thanks guys, I will try Brandons solution which seems to be kinda the same Benjamin offered?! Anyway, thank you.  

---

## 1 answers

### Answer by username_3 on 2014-09-23. Score: 1 | Accepted answer

Matrix fields can only be used as custom fields, on an element.

If you really want to use them, you would need to create a custom Element Type (see the resources at the bottom of <http://buildwithcraft.com/docs/plugins/working-with-elements>), and then create a Matrix field that is associated with your element type’s field layout.

> **Comments:**
> **username_4**: Is it applied for craftcms 3.x as well or we can add directly now without creating the element type.  
> **username_3**: @inrsaurabh Same answer applies to Craft 3  

---

