Ok there is getName and getLabel for form elements, but is there something for getType()?
I am using a loop and when it is a checkbox I want it to do something else.
You'll have to use this:
if (strcmp($myCheckbox->getAttribute('type'), 'check') === 0) { // Do stuff... }
I am unable to replicate this instruction in Phalcon 2.0.8:
{% for element in my_form %} {{ element.getAttribute('type')|json_encode }} {% if element.getAttribute('type') == 'hidden' %} {{ element.render() }} {% endif %} {% endfor %}
The getAttribute('type') returns null for every element in my form.
My solution is:
public function beforeValidation($data, $entity, $messages) { $elements = $this->getElements(); foreach ($elements as $element){ $is_checkbox = is_a($element, 'Phalcon\Forms\Element\Check'); if ($is_checkbox){ // do stuff } } }