getting id/name attribute from HTML elements


I’ve been trying to write some component for form client-side validation. The goal is to enable it without having to rewrite all forms already made … or maybe some small modifications (it uses a JQuery plugin ). The principle is to write a component that wraps all CHtml:: calls done to create the form, and handles the JS initialisation for the validate JQuery plugin. Rules are the ones defined at the model level, or at least the ones which have a meaning on the client side …(I don’t know if it’s a good idea, and there maybe a more simple way to achieve it).

Anyway, at a certain point, the view calls …


with …


        public function activeTextField($model,$attribute,$htmlOptions=array()){


 		$html = CHtml::activeTextField($model,$attribute,$htmlOptions);

 		$this->_validators[$attribute]['id'] = $htmlOptions['id'];

 		return $html;


The point is that the component wants to get the HTML element id attribute (it is neede for JS initialisation) and as I didn’t know how to do, I’ve (shame on me) modified CHtml ( :o … it’s just for test, I promise !) so CHtml::activeTextField accepts a reference for $htmlOptions.

Is there a better way to do it ? should I just copy the internal CHtml 'id' resolution logic ?



You can use CHtml::activeId() to get the ID.

oups … missed it  :-[

thanks Quiand