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

can we set html attributes in phalcon forms.

can we set html stttibutes in phalcon forms..... example.... i want to set

<div class="icheckbox_flat-green checked" style="position: relative;" aria-checked="true" aria-disabled="false">
    <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%;margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;">
      <
    </ins>
</div>

to all the checkboxes in the form itself...... can i do it in this way(bysetting them in the forms ).???? Please help!!!



85.5k
  new Checkbox("my_name", [ 
      "class" => "myClass",
      style = "margin-top: 10px;" ,
      "myCustomProperty" => true 
      ]
  )

?

edited Nov '16

thanks for the reply!!! work is half done.... i want to run an extra <div> for all the checkboxes... Can you help?



85.5k
edited Nov '16

you cant do that in the php.

but u can wrap them with that div in phtml, volt file ?

or extend the checkbox class and write your own render function for them

edited Nov '16

How can i extend the checkbox class. Can you give an example?



85.5k
edited Nov '16

use Phalcon\Forms\Element;
use Phalcon\Forms\ElementInterface;

class myCheckbox extends Element implements ElementInterface {

    public function render($attributes = null){
        //var_dump($this);

        return "<div class="whatever"><input type checkbox name .. > </div> ...";
    }
}

source here: https://github.com/phalcon/cphalcon/blob/master/phalcon/forms/element/check.zep