PHP code example of yannkost / craft-easy-form

1. Go to this page and download the library: Download yannkost/craft-easy-form 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/ */

    

yannkost / craft-easy-form example snippets


use yii\base\Event;
use yannkost\easyform\services\Webhooks;
use yannkost\easyform\events\WebhookEvent;

Event::on(Webhooks::class, Webhooks::EVENT_BEFORE_SEND, function (WebhookEvent $e) {
    $e->headers['Authorization'] = 'Bearer ' . App::env('MY_WEBHOOK_TOKEN');
    // $e->isValid = false;  // cancel this webhook
});

use yii\base\Event;
use yannkost\easyform\controllers\SubmissionsController;
use yannkost\easyform\events\SubmissionValidationEvent;

Event::on(
    SubmissionsController::class,
    SubmissionsController::EVENT_BEFORE_VALIDATE,
    function (SubmissionValidationEvent $e) {
        // `serverTier` is declared as a frontend field on the form
        $e->submissionData['serverTier'] = lookupTier($e->submissionData['email'] ?? '');

        // …or reject the whole submission:
        // $e->isValid = false; $e->message = 'Nope';
    }
);

POST /admin/easy-form/submissions/export                       # enqueue → { token, statusUrl }
GET  /admin/easy-form/submissions/export-check?key=<token>     # { ready, downloadUrl }
GET  /admin/easy-form/submissions/export-download?key=<token>  # streams the CSV
bash
  php craft easy-form/submissions/prune            # uses configured retention
  php craft easy-form/submissions/prune --days=90  # override
  php craft easy-form/submissions/prune --dry-run  # preview
  
bash
php phpunit.phar