Answer the question
In order to leave comments, you need to log in
How to add a category without refreshing the Yii page?
Hello! There was a need to quickly add a new category when adding a new article to the site. I realized that I need to use AJAX, created a form, made ajaxLink, wrote a handler for saving data.
Everything is fine, yes, the page reloads and I get to the form page, which is rendered through renderPartial.
Here is the handler:
public function ActionQuickcat()
{
$model = new CategoryForm;
$form = new CForm($model->areasSettings(), $model);
if($form->submitted('submit') && $form->validate())
{
$newCat = new Coursecat;
$newCat->attributes=$_POST['CategoryForm'];
if($newCat->validate())
{
$newCat->save();
exit;
}
}
$this->renderPartial('quickform', array('model'=>$model, 'form'=>$form));
}
echo CHtml::ajaxLink('Создать категорию', $this->createUrl('coursecat/quickcat'),
array('update' => '.modal-body'),
array('id'=>'login-btn', 'data-toggle'=>'modal', 'data-target'=>'#myModal','onclick' => "$('#myModal').modal('show')")
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question