PHP code example of phloxcz / forms-editor

1. Go to this page and download the library: Download phloxcz/forms-editor 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/ */

    

phloxcz / forms-editor example snippets


protected function createComponentArticleForm(): Form
{
    $form = new Form;

    $form->addText('title', 'Nadpis');

    $form->addEditor('content', 'Obsah článku')
         ->setUploadRoute($this->link('Article:wysiwygUpload'))
         ->setRequired('Zadejte obsah.');

    $form->addSubmit('save', 'Uložit');
    $form->onSuccess[] = [$this, 'formSucceeded'];

    return $form;
}

public function formSucceeded(Form $form, \stdClass $values): void
{
    // ⚠️  Vždy sanitizujte HTML před uložením!
    $safe = $this->htmlPurifier->purify($values->content);
    $this->articles->save(['title' => $values->title, 'content' => $safe]);
    $this->redirect('this');
}

class ArticlePresenter extends BasePresenter
{
    use \Phlox\Forms\Editor\ImageUploadTrait;

    // Volitelné přepsání výchozích hodnot:
    protected string $wysiwygUploadDir = __DIR__ . '/../../www/uploads/editor/';
    protected string $wysiwygUploadUrl = '/uploads/editor/';
    protected int    $wysiwygMaxSize   = 10 * 1024 * 1024; // 10 MB
}

$router->addRoute('article/upload', 'Article:wysiwygUpload');

// app/Bootstrap.php nebo Services.php
\Phlox\Forms\Editor\EditorInput::register('addEditor');

$config = \HTMLPurifier_Config::createDefault();
$config->set('HTML.AllowedElements',
    'p,h1,h2,h3,h4,h5,h6,strong,em,u,s,code,pre,blockquote,ul,ol,li,a,img,table,thead,tbody,tr,th,td,div'
);
$config->set('HTML.AllowedAttributes',
    'a.href,a.target,img.src,img.alt,img.class,*.class'
);
$purifier = new \HTMLPurifier($config);
$safeHtml = $purifier->purify($rawHtml);