1

In the Sprout Forms plugin, is there a way to modify the EntryModel through sproutForms.onBeforeSaveEntry? I have a plugin that sends a cURL request onBeforeSaveEntry, and I'd like to grab the response from that and deliver it to the user on the thank you page.

I've tried setting new properties on the $event object but I'm getting errors, so maybe my approach is wrong? Been searching, but unable to find how to get it done.

2

So it turns out you can modify an existing property like this:

$event->params['entry']->getContent()->existingProperty = 'new value';

What I ended up doing was using a hidden field and then updating the value of that from the sproutForms.onBeforeSaveEntry event:

craft()->on('sproutForms.onBeforeSaveEntry', function(Event $event) {
    $entry = $event->params['entry'];
    $entry->getContent()->subscribeStatus = 'success';
});

Since that property can be set depending on what the response is from the cURL post, it's possible to deliver success/error messages to users on the thank you page and prevent the subscribe from silently failing in the background.

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.