Array Message

Hey all,

I’m probably missing something really obvious, but I’m trying to use “‘multiple’ => true,” with a text field inside a custom module, and on the front-end, I’m getting text that literally says “array”, in place of what the actual content should be.

I’m not seeing any other errors, plugins are disabled, and I’m using the latest version of the plugin (on a local install).

I’ve tried copying other modules and using ‘multiple’ => true as well and am getting the same error / message.

I’ve probably just worked too much this weekend and I’m not thinking clearly :). Any thoughts?

Hey Desmond,

When using multiples the value of a setting will be an array with values for each of your text fields. For example, if you have a field with a key of “my_text” you can access the values like this…

for ( $i = 0; $i < count( $settings->my_text ); $i++ ) {
    echo $my_text[ $i ];
}

Let me know if you have any questions about that.

Justin

Awesome, thanks Justin. I’ll give it a try and let you know if I have any issues.

So it looks like I’m finally getting around to testing this out (been extremely busy!).

Unfortunately I’m not having any success. I’ve gone through the various threads and looked at the code within the page builder as well. I’m kicking myself because this should be so simple.

Would it be possible to get a quick and dirty snippet of what I’m trying to achieve?

Really something basic like a repeating text field (that works!) would be fantastic.

Something like this:

                    'multiple_test'          => array(
                        'type'          => 'text',
                        'label'         => __('Multiple Test', 'fl-builder'),
                        'multiple'      => true
                    ),

I just need the frontend.php counter-part.

Thanks for your help as always.

Hey Desmond,

It looks like your field config is correct. This frontend.php code should work for that…

for ( $i = 0; $i < count( $settings->multiple_test ); $i++ ) {
		
	if ( ! is_object( $settings->multiple_test[ $i ] ) ) {
		continue;
	}
	
	echo '<div class="multiple_test">' . $settings->multiple_test[ $i ] . '</div>';
}

Let me know if it doesn’t.

Justin

Strange, I have this code:

<div class="content-should-be-within">
<?php
    for ( $i = 0; $i < count( $settings->multiple_test ); $i++ ) {

        if ( ! is_object( $settings->multiple_test[ $i ] ) ) {
            continue;
        }

        echo '<div class="multiple_test">' . $settings->multiple_test[ $i ] . '</div>';
    }
?>
</div>

And I’m not seeing anything. Checking chrome inspector pulls up a blank (except for the surrounding div tags). I’ve also double checked that there is indeed data being saved in the builder. I’ve also refreshed the cache for the page builder.

Any ideas?

Hey Desmond,

Do you have WP_DEBUG on? There might be an error coming up. Also, can you send me the module so I can test on my end?

Thanks,
Justin

[Content Hidden]

Thanks, Desmond. My bad on this one, it looks like you don’t need this code after all…

if ( ! is_object( $settings->multiple_test[ $i ] ) ) {
    continue;
}

Remove that and you should be good to go!

Justin

Yep! That did it. Great support as always!

Great! Have fun :slight_smile: