Why doesn't my plugin load in production?

207 Views Asked by At

I need to implement Google reCaptcha in the contact forms for my application, so I tried installing a simple reCaptcha plugin (this one seemed to be simple enough: https://github.com/agiletechvn/Recaptcha). So I followed the instructions.

I installed it with composer, loaded it with bin/cake plugin load, verified there is a "$this->addPlugin('Recaptcha');" in my Application.php and made the appropriate changes to my controller and view. In localhost everything seems to be working just fine (and debugkit tells me the plugin is being loaded correctly), but being a reCaptcha I can't test it unless it is a live server. So I uploaded all the files (including the corresponding folder in vendor and updating the cakephp-plugins.php file). The issue is it keeps giving me a "Component class RecaptchaComponent could not be found." error. What am I missing or missplacing?

My controller:

class ClientsController extends AppController
{
    public function initialize() {
        parent::initialize();
        
        $this->loadComponent('Recaptcha.Recaptcha', [
            'enable' => true,
            'sitekey' => '6Lf2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', //the sitekey I got from the Google reCaptcha API
            'secret' => '6Lf2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', //the secret key I got from the Google reCaptcha API
            'type' => 'image',
            'theme' => 'light',
            'lang' => 'en',
            'size' => 'compact'
        ]);
    }

    public function contact()
    {
        $client = $this->Clients->newEntity();
        if ($this->request->is('post')) {
            if ($this->Recaptcha->verify()) {
                $client = $this->Clients->patchEntity($client, $this->request->getData());
                if ($this->Clients->save($client)) {
                    $this->Flash->success('Your message has been saved.');
                    $this->redirect($this->referer());
               } else {
                   $this->Flash->error('There was a problem with the Contact Form. Please retry.');
                   $this->redirect($this->referer());
                }
            } else {
                $this->Flash->error('Verify the Google Recaptcha before continuing.');
            }
        }
        $this->set(compact('client'));
    }
}

My View:

<?= $this->Form->create($client); ?>
  <?= $this->Form->control('first_name',['label' => 'Firt name:']); ?>
  <?= $this->Form->control('last_name',['label' => 'Last name:']); ?>
  <?= $this->Form->control('email', ['label' => 'Email:']) ?>
  <?= $this->Form->control('phone', ['label' => 'Phone number:']) ?>
  <?= $this->Form->control('comments', ['label' => 'Message:','rows' => 3]) ?>
  <?= $this->Recaptcha->display(); ?>
  <?= $this->Form->button('Send') ?>
<?= $this->Form->end(); ?>

The error I get:

Error: [Cake\Controller\Exception\MissingComponentException] Component class RecaptchaComponent could not be found. (/home1/viajejuw/public_html/vendor/cakephp/cakephp/src/Controller/ComponentRegistry.php:101)

Disclaimer: I don't have terminal connection available in the production server.

1

There are 1 best solutions below

2
On BEST ANSWER

Sounds like you maybe didn't upload the updated autoloader files. Do not just transfer selected vendor files, if you don't have shell access and cannot run composer on your server, you should transfer all vendor files, unless you have a fail-proof way of tracking which files have been changed.

In 9 out 10 cases when a class is missing in your target environment, but it is present in your local environment, the file either wasn't uploaded, has the wrong permissions, isn't present in the the autoloader, or there's a typo that isn't compatible with case-sensitive filesystems.