PHP code example of jakercz / nette-mailerlite

1. Go to this page and download the library: Download jakercz/nette-mailerlite library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jakercz / nette-mailerlite example snippets


use MailerLite\MailerLiteForm;

protected function createComponentMailerLiteForm(): MailerLiteForm
{
  $mailerLiteForm = new MailerLiteForm('SET API KEY', $this->translator);
  $mailerLiteForm->setGroupID('SET GROUP ID');
  //$mailerLiteForm->setTemplatePath(__DIR__ . '/MailerLiteForm.latte');
  $mailerLiteForm->onSuccess[] = function (array $values) {
       $this->flashMessage('Email has been save!', 'success');
       $this->redirect('this');
  };
  $mailerLiteForm->onError[] = function ($error) {
       $this->flashMessage('Error! ' . $error->message, 'danger');
       $this->redirect('this');
  };
  return $mailerLiteForm;
}

use MailerLite\MailerLiteForm;


 public function succeededForm(Form $form, ArrayHash $values)
 {
     $mailerLiteForm = new MailerLiteForm('SET API KEY', $this->translator);
     
     if ($values->newsletter == 1){
         $subscriber = [
           'email' => $values->email,
         ];
         $mailerLiteForm->getGroupApi()->addSubscriber('SET GROUP ID', $subscriber);
     }
 }
json
"php": ">=7.0.0",
"mailerlite/mailerlite-api-v2-php-sdk": ">=0.2.1"