1

I am trying to get the value of a field from a freeform event. Specifically I'm trying to see if a particular checkbox is in a form submission.

craft()->on(
    "freeform_submissions.onBeforeSave",
    function (Event $event) {
        $submission = $event->params["model"];
        $field = $submission['fieldMetadata']['checkbox_handle'];

This works to this point. I see if I do Craft:dd($field); I have a checkboxField object. But from here on I can't get any info about that field.

        $id = $field->id; // or:
        $handle = $field->handle; // and any other properties

This throws: Fatal error: Cannot access protected property Solspace\Freeform\Library\Composer\Components\Fields\CheckboxField::$id.

If I try:

        $id = $field['id'];

I get: Fatal error: Cannot use object of type Solspace\Freeform\Library\Composer\Components\Fields\CheckboxField as array

The properties and methods are listed at: https://solspace.com/craft/freeform/docs/field/, but I can't access the properties. I can call the render() method which works and that outputs html. I'm sure its something obvious, but I'm missing it.

1 Answer 1

2

To answer my own question, this is what I found. The answer is to use get... methods.

craft()->on(
    "freeform_submissions.onBeforeSave",
    function (Event $event) {
        $submission = $event->params["model"];
        $field_item = $submission->fieldMetadata['field_handle'];
        $field_value = $field_item->getValue();

    }
);

The $field_item->getValue() can be $field_item->getId() or $field_item->getHandle() and so on.

The properties listed here: https://solspace.com/craft/freeform/docs/field/ can be used by turning the property into a method and prepending get.

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.