Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
2 added 7 characters in body; edited tags
source | link

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. FromBut 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.

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. From here I can't get any info about that field.

        $id = $field->id; 

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.

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
source | link

How to access a freeform field object's properties from an event

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. From here I can't get any info about that field.

        $id = $field->id; 

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.