PHP code example of mindy / form

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

    

mindy / form example snippets




namespace Mindy\Form\Widget;

use Mindy\Form\Widget;
use Mindy\Helper\JavaScript;
use Mindy\Helper\JavaScriptExpression;

class RatingWidget extends Widget
{
    public $options = [];

    /**
     * @return string
     */
    public function render()
    {
        $field = $this->getField();
        $jsOptions = JavaScript::encode(array_merge([
            'starType' => 'i',
            'numberMax' => 5,
            'score' => $field->getValue(),
            'click' => new JavaScriptExpression('function(score, evt) {
                $("#' . $field->getHtmlId() . '").val(score);
            }')
        ], $this->options));
        $js = "<div id='{$field->getHtmlId()}_rating' class='rating-input'></div><script type='text/javascript'>$('#{$field->getHtmlId()}_rating').raty({$jsOptions});</script>";
        return $field->renderInput() . $js;
    }
}



class MyForm extends Form
{
    public function getFields()
    {
        return [
            'rating' => [
                'class' => CharField::class,
                'widget' => new RatingWidget
            ]
        ];
    }
}