We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Extends element Form

Have you got a more complex example code about to extends an Element ?

"In addition to the form elements provided by Phalcon you can create your own custom elements:

<?php
use Phalcon\Forms\Element;
class MyElement extends Element
{
    public function render($attributes=null)
    {
        $html = //... produce some html
        return $html;
    }
}

I tried to extends an Element, when i POST the Form how to read the value posted in the render method ?

$form = new Form($model);
$form->add(new Map("latlng"));
$form->bind($_POST,$model);

class Map extends \Phalcon\Forms\Element {

public function render($attributes=null)
{

      $html = "" //... produce some html
      $html .= Tag::hiddenField(array($this->getName(), "value" => $this->getValue()));

      ....

      return $html;
}
}

$this->getValue(); IS EMPTY, NO VALUE FROM THE POST and how to add the attributes ?

public function render($attributes = null)
{
    $attrs = $this->prepareAttributes($attributes);
    return "..." . \Phalcon\Tag::hiddenField($attrs);
}