Trying to Extend to Form Class getting (Call to a member function selectID() on null) Using Concrete CMS 8.5.7)

I need a new form select to allow me to set a different id and name in a select form. So I am trying to extend the form class. I did the following. concrete\packages\concrete_form_addon\src\Concrete\Form\Service\Form2.php

namespace Concrete\Package\ConcreteFormAddon\Form\Service;

class Form2 extends \Concrete\Core\Form\Service\Form {
    public function selectID($key, $optionValues, $valueOrMiscFields = '', $miscFields = []) {
        working code for the option

Then in the class file I have

namespace Concrete\Package\ConcreteFormAddon;

use Concrete\Core\Asset\Asset;
use Concrete\Core\Asset\AssetList;
use Concrete\Core\Package\Package;
use Concrete\Core\Page\Page;
use Concrete\Core\Support\Facade\Route;
use Concrete\Core\Support\Facade\Config;
use Whoops\Exception\ErrorException;

class Controller extends Package {
    protected $pkgHandle = 'concrete_form_addon';
    protected $appVersionRequired = '8.4';
    protected $pkgVersion = '0.8.7';
    protected $pkgAutoloaderRegistries = [
        'src/Concrete/Form' => 'Concrete\Package\ConcreteFormAddon\Form',
    public function getPackageDescription() {
        return 'Add custom form functions to Concrete CMS';
    public function getPackageName() {
        return 'Concrete Form Add-On';

Then the line of code that calls it:

<?= $form2->selectID('', $manufacturers, $product->getManufacturer() ? $product->getManufacturer()->getID() : '',  ['id' => 'pManufacturer' . $pID, 'name' => 'pManufacturer[]', 'class' => 'selectize pricing-fields']) ?>

If I put the first bit of code in the core file it works fine if I use $form->selectID so there is something wrong with the way I’m setting up the class I believe.

How do you create $form2 variable - are you doing something special (it’s null so I am guessing you have not initialized it?)

I took the public function select($key, $optionValues, $valueOrMiscFields = ‘’, $miscFields = []) from the core form/service/form.php and changed it from:

$str = '<select id="' . $id . '" name="' . $key . '"' . $this->parseMiscFields('form-control', $miscFields) . '>';


$str = '<select' . (empty($key) ? '' : ' id="' . $id . '" name="' . $key . '"') . $this->parseMiscFields('form-control', $miscFields) . '>';

But I was wanting to extend the class to add my own so I didn’t have to change the core files.
Does that make sense?

I guess I should add I copied everything from the

public function select($key, $optionValues, $valueOrMiscFields = ‘’, $miscFields = []) 

and made the change to the line in the other reply, if I paste the code I made as a new public function selectID($key, $optionValues, $valueOrMiscFields = ‘’, $miscFields = []) in the \Form\Service\Form.php file it works. I just cannot figure out how to set it up as an extended class.

It seems you are trying to override the form class in a way that won’t allow you to override it.
You should instead use $this->app->bind() in your controller’s on_start method.

Having said so I don’t think you need to override it at all. Since you want to use that selectID() method and it’s not going to be available to other processes, you should simply make sure your custom class extends the original one and then when you need to generate a form, just instantiate your own class and use it.

I figured it all out right before I ran out of time Friday.
It was simple once I figured out what I had to do, but yes I added to the main url:
$form2 = $app->make('helper/form2');

and added to the controller:

    public function registerHelpers()
        $binds = [
            'helper/form2' => '\Concrete\Package\ConcreteFormAddon\Form\Service\Form2'
        foreach ($binds as $key => $value) {
            $this->app->bind($key, $value);

    public function on_start()

That all made it were the Form2.php is working so I could modify the code there, keeping me from changing the core Form.php