[SOLVED] button to create db entry

I would like to create a button that can be used to populate a table in my db with a single click.

I am just not sure what I need to do here to make this happen. Can I assign a method to be executed by a button? Or just have values picked up in my controller? Below is something like what I want to execute but through a button.

public function addInterest($interest)




        return $interest->save();


Can someone point me in the right direction on what I should be looking at doing?

The button is going to have to either submit a form or a get request. I’d just write it in JQuery and push the request up to a controller/action using .get().


Disable the button when they press it so they can’t just spam your database, if you use jquery you can return a status and return a message.

Packing your addInterest method invoking into action will be needed. I am not sure what class this method is member of - assuming controller, in the action method you need to create object of Interest type and invoke addInterest method.

For adding button you can use ajax or regular style. In the latter case create simple form contains only submit button. For ajax use CHtml::ajaxButton(). In both cases use created action as a target.

Thanks Luke Jurgs and KEo for the help. I ended up just executing an action through an ajaxLink to accomplish what I needed here.

In case anyone else needs some reference material on the same subject…



For reference. Here is the code for what I ended up doing to complete what I needed.

[SOLVED] NULL instead of value on Yii DAO SQL INSERT: bindValue