1

I'm basically wanting to manipulate user-submitted forms through the use of SproutForms. Basically, the user enters their form data, submits it, where it's recorded as a SproutForm entry. When that happens, I also want it to create an entry in a channel with the same data, so that I can freely use them in templates (showing users a list of their submissions).

All this would be simpler if SproutForms had some templating tags to output entries, but from looking through the plugin, I don't think thats possible.

Anyway, so an additional plugin could have something like this:

public function init() {

    // Support Sprout Forms plugin
    craft()->on('sproutForms.saveEntry', function(Event $event) {
        $entry = $event->params['entry'];
        craft()->entries->saveEntry($entry);
    });

}

But that doesn't seem to work. Any ideas, or a better suggestion?

2

As of Sprout Forms 0.8.4 this is not possible. It is on our list to allow more customization over the form entries and how they are output on the front end so this will be possible in the future. If you'd like us to prioritize this functionality, drop us a note and we're happy to have that conversation.

If you wish to save a Craft Entry after the Form Entry is saved, you're using the right Event above. One thing you will want to be careful of is that the Sprout Forms $entry value is a SproutForms_EntryModel and the variable you need to pass to the craft()->entries->saveEntry($entry) method is a Craft EntryModel.

To do this you'll need some code to hand off the field values on the Form Entry to the field values on the Craft Entry:

public function init() {

    // Support Sprout Forms plugin
    craft()->on('sproutForms.saveEntry', function(Event $event) {

        // SproutForms_EntryModel
        $formEntry = $event->params['entry'];

        // Craft EntryModel
        $craftEntry = new EntryModel;

        // Map your Form field values to the Entry field values
        $craftEntry->fieldName = $formEntry->fieldName;

        craft()->entries->saveEntry($craftEntry);
    });

}

That said, this method feels pretty messy to me. Duplicating data is a great way to create great pains for yourself down the road. If you're set on doing this on your own, I'd recommend to create a custom plugin with and a variable that queries the Sprout Forms data how you'd like.

{% set userFormSubmissions = craft.myCustomPlugin.sproutFormsQuery(userId) %}

When Sprout Forms gets around to adding this functionality, you can swap out your custom tag for the native Sprout Forms one and ditch the custom plugin.

  • Thanks Ben, indeed its not the best solution, and because I'm already going down a 'create-your-own-plugin' road, I think querying the forms directly is the best way to go. At least this gives me a good chance to get into plugin dev! – crawf Jan 21 '15 at 5:56
  • Sounds good @crawf. That should be a nice little plugin to get started with. All you'll probably need is a PluginClass.php file, a variable that hands off responsibility to the service layer, and a service to do the querying. – Ben Parizek Jan 21 '15 at 5:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.