I am using CForm with some customized configurations for user inputs. The configurations of the CForm are altered via ajax on the fly so that I can add or delete CFormElements according to some preferences. This works great but I got problems adding a simple ajaxSubmitButton to my CForm configuration.
Is there an elegant way to add ajaxSubmitButtons to a CForm object? I don’t want to use CActiveForm as it isn’t that flexible
Thanks in advance!
Ok, after asking it came to my mind that I could use this workaround. Instead of adding the buttons via form-config I render the button in the partial view between the two <form> tags like this.
foreach($form->getElements() as $element)
Thanks for sharing Haensel…
i’ve got the solution.
assign key ‘attributes’ to your button with an array as value
assign key ‘ajax’ in array attributes and configure linke ajaxButton, ajaxSubmitButton.
'buttons' => array(
'login' => array(
'type' => 'submit',
'label' => 'Speichern',
'attributes' => array(
'class' => 'submit',
'ajax' => array(
'type' => 'POST', //request type
'url' => Yii::app()->createUrl($this->getId() . '/AjaxTest'), //url to call.
'update' => '#content', //selector to update
Thanks! Really nice find!