0

I'm trying to work with the Sprout Forms events to grab a variable from the form and add it to a filename also uploaded through the same form. I am extremely stuck and so far I can't even confirm that the event itself is working. What I need to do is grab the variables from the form on the event after save. To start, how do I print the variables in the event? Do I need to do a second function?

Event::on(Entry::class, Entry::EVENT_AFTER_SAVE, function(Event $event) {
        $formEntry = $event->sender;
        $fieldHandle = $formEntry->getRequiredParam('fieldHandle');
        print $fieldHandle;
    });

Also, dumb question, do events need to be inside of a Controller?

2
  • You want to print it out to see if your event is being hit? You can use die($fieldHandle); and that'll halt the rest of the request while outputting the value. php.net/manual/en/function.die.php
    – Brad Bell
    Commented Jul 12, 2021 at 0:26
  • Make sure the 'Entry' variable in your code refers to the Sprout Forms Entry Element and not the Craft Entry Element. Sometimes an editor can autocomplete the wrong reference there: use barrelstrength\sproutforms\elements\Entry. And, as die works like Brad described, if you need a look at the whole event, Craft provides a statement that can output the whole event object \Craft::dd($event); Commented Jul 13, 2021 at 12:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.