Hi everyone!
I need to send a value from a dropdownlist to the controller in order to update a record.
So far I putt this in the view:
<div class="form_row">
<?php
//
// THE DROPDOWN LIST FILLED WITH AUTHORS
//
echo CHtml::dropDownList('new_author_id', null, Chtml::listData(Author::model()->findAll(), 'id', 'lastname'));
//
// THE AJAX LINK
//
echo CHtml::ajaxLink("Add author",
CController::createUrl('publications/AddAuthorAndUpdateAjax'),
array('update' => '#ajax_content', 'data' => array(
'publication_id' => $_GET['id'], // The current publication
'new_author_id' => '' // HERE I NEED TO GET THE SELECTED VALUE FROM THE DROPDOWN LIST
)
)
);
?>
</div>
And in the controller:
public function actionAddAuthorAndUpdateAjax(){
$author_id = $_GET['new_author_id']; // HERE I WANT TO GET THE VALUE!!!
$publication_id = $_GET['publication_id'];
//
$record = new PublicationAuthor;
$record->author_id = $author_id;
$record->publication_id = $publication_id;
$record->save();
//
$publication = Publication::model()->findByPk($publication_id);
//
$this->renderPartial('_related_authors', array('authors' => $publication->getAuthors()));
}
The thing is if I hardcode the value in the ajax statement it works fine, but I need to get the selected value from the dropdown list.
With jQuery, I would get that value with -> $("select#new_author_id").val();
How I should pass the value???
Thanks in advance!!!