PHP code example of phloxcz / forms-taginput

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


\Phlox\Forms\TagInput\TagInputExtension::register();

$form->addTagInput('tags', 'Tags:')
     ->setItems([1 => 'PHP', 2 => 'Nette', 3 => 'MySQL'])
     ->setTheme(TagInput::THEME_BOOTSTRAP);

// In your presenter:
$form->addTagInput('tags', 'Tags:')
     ->setSelection($this->tagRepository->findAll(), 'id', 'name')
     ->setSearchUrl($this->link('searchTag!'))
     ->setTheme(TagInput::THEME_BOOTSTRAP)
     ->setAllowNew(false);

// Signal handler:
public function handleSearchTag(string $q = ''): void
{
    $this->sendJson($this['myForm']['tags']->fetchData($q));
}

// Flat array — all values together
$tags = $form['tags']->getValue();
// e.g. [1, 3, "brand new tag"]

// Split by origin
$split = $form['tags']->getSplitValue();
foreach ($split['picked']  as $id)    { /* existing record ID */ }
foreach ($split['created'] as $label) { /* new free-text tag  */ }