zoidberg
(Dr Zoidberg0)
September 30, 2011, 2:28pm
1
Hello!
I’m new to Yii and I’m trying to build a form with radio buttons. on change it should update a model.
A user has a status that should be changed as soon as a radio button is clicked
This is my code:
echo CHtml::beginForm();
echo CHtml::activeRadioButtonList($model, 'status', Lookup::items('Status'),
array( 'onclick'=> 'this.form.submit()'));
echo CHtml::endForm();
How can I specify which action should be called? How can I do this with ajax in order to update a list on the same site?
Thank you!
aruna470
(Aruna470)
September 30, 2011, 2:52pm
2
//you can do it by setting the form action before submit the form.Try with below coding
echo CHtml::activeRadioButtonList($model, 'status', Lookup::items('Status'),
array( 'onclick'=> 'javascript:this.form.action=\'index.php?r=controller\action\';this.form.submit()'));
zoidberg
(Dr Zoidberg0)
September 30, 2011, 4:51pm
3
//you can do it by setting the form action before submit the form.Try with below coding
echo CHtml::activeRadioButtonList($model, 'status', Lookup::items('Status'),
array( 'onclick'=> 'javascript:this.form.action=\'index.php?r=controller\action\';this.form.submit()'));
It works! Thank you very much!!!
Is this also possible with ajax? With the above method I have to redirect back to the page from the action.
BStep
(R Brad Stephens)
September 30, 2011, 8:27pm
4
Yes, you just need to change the onClick event to something like:
js:function(){
var myformdata = $('#my_form_id').serialize();
$.ajax('/controller/action',{
data:myformdata,
success:function(msg){
alert(msg);
}
});
}
zoidberg
(Dr Zoidberg0)
October 2, 2011, 11:10am
5
BStep:
Yes, you just need to change the onClick event to something like:
js:function(){
var myformdata = $('#my_form_id').serialize();
$.ajax('/controller/action',{
data:myformdata,
success:function(msg){
alert(msg);
}
});
}
Thank you very much!
I was able to implement it
Great community!!!