Creating an Express Object Form

Hi, I’m trying to build an Express Object Form in a single page controller. This code works:

$form = $object->buildForm(‘Form’);
$form->addFieldset(‘Basics’)
->addAttributeKeyControl(‘page_name’)
->addAttributeKeyControl(‘parent_page_path’);
$form->save();

So I expected I could do this as well:

$form = $object->buildForm(‘Form’);
$form->addFieldset(‘Basics’);
$form->addAttributeKeyControl(‘page_name’);
$form->addAttributeKeyControl(‘parent_page_path’);
$form->save();

but that bombs out with a error: error":{“type”:“Error”,“message”:“Call to undefined method Concrete\Core\Express\ObjectBuilder\FormBuilder::addAttributeKeyControl()”,“code”:0,“file”:

What I had be hoping to do was add the attribute control keys in a foreach, something like:

$form = $object->buildForm(‘Form’);
$form->addFieldset(‘Basics’);
foreach($handles as $handle){
$form->addAttributeKeyControl($handle);
}
$form->save();

I’ve been coming back to this problem for over a year now and would like to finally get it figured out as I am upgrading all my packages for Concrete 9.cx and PHP 8x. If anyone can point me in the right direction it would really be appreciated.

Thanks

Hmm let me take a look at this and I’ll get back with you.

Thanks Evan, I’m really stuck on this one.

buildForm returns an instance of the Concrete\Core\Express\ObjectBuilder\FormBuilder class, but addFieldSet actually returns an instance of the Concrete\Core\Express\ObjectBuilder\FieldsetBuilder class. But in your second example you’re running addAttributeKeyControl on the FormBuilder class instead of the FieldsetBuilder class.

Does something like this work?

$form = $object->buildForm(‘Form’);
$fieldset = $form->addFieldset(‘Basics’);
foreach ($handles as $handle) {
    $fieldset->addAttributeKeyControl($handle);
}
$form->save();

Works perfect Andrew, thanks so much!

2 Likes

Awesome, glad to hear it!

1 Like