pyrocms

How to store Contact form data in Database in PyroCMS 3.x


How do I store the data in the Database for a website using pyrocms.

I currently use the contact plugin and need to store the data in mysql.

If anyone has done this, I would appreciate the help!


Solution

  • The contact plugin does not capture data, but you can indeed save the input by slightly extending it.

    You will need to have a table made to put it in. Otherwise, you could make a Stream to stuff the data into as well.

    The easiest way is likely to use the posted callback on the ContactFormBuilder.

    Something like this:

    use \Anomaly\ContactPlugin\Form\ContactFormBuilder;
    
    app(ContactFormBuilder::class)->listen('posted', function(ContactFormBuilder $builder) {
        YourStreamModel::create($builder->getFormInput());
    }