I am working on job portal,and have a search module for employers to search for application.I want to use ajax to list the application after search, listing the results in the same page.How should I do it.?,Below is the screenshot of the module.Have tried the following things.
//Contoller Code//
public function actionSearch()
{
$model = new SearchEmployee();
/*Getting Data From Search Form For Processing */
if (isset($_POST['SearchEmployee'])) {
$model->attributes = $_POST['SearchEmployee'];
$category = $_POST['SearchEmployee']['category'];
$skills = $_POST['SearchEmployee']['skills'];
$experience = $_POST['SearchEmployee']['experience'];
$ajaxmodel = SearchEmployee::model()->find(array(
'select' => array('*'), "condition" => "category_id=$category AND key_skills like'%$skills%'AND experience=$experience",
));
if($model==null)
{
Yii::app()->user->setFlash('success', "No Results");
$this->renderPartial('search');
}
else
{
$this->renderPartial('search', array('model' => $ajaxmodel));
Yii::app()->end();
}
}
// In views,Not posting full codes just codes to show the ajax results,//
<div class="view">
<h1>Results </h1>
<div class="view" id="id">
<h1> Records Display </h1>
<h4>Name: <?php echo $form->labelEx($model,'skills Required'); ?></h4>
<h4>Skills: <?php echo $form->labelEx($model,'Skills Required'); ?></h4>
<h4>Experience: <?php echo $form->labelEx($model,'Skills Required'); ?></h4>
<h5> <?php echo CHtml::submitButton('VIew Details'); ?></h5>
</div>
</div>
Is this way to do...
In your view just enable ajax, for example:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'client-document-form',
'method' => 'post',
'action' => $url,
'enableAjaxValidation' => false,
'errorMessageCssClass' => 'required_field_text'
)); ?>
This line enableAjaxValidation => true
need be true also in your actions add this line $this->performAjaxValidation($model);
UPDATE:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'update-profile-form',
'enableAjaxValidation' => true,
'errorMessageCssClass' => 'required_field_text',
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => false,
'hideErrorMessage' => true,
'beforeValidate' => 'js:function(form) {
return validate.beforeValidate("update-profile-form");
}',
'afterValidate' => 'js:function(form, data, hasError) {
validate.afterValidate(data, "update-profile-form");
}'
),