I am new in yii framework.I am doing a search search operation using yii framework.My requirement is to check textbox value is null or not in the controller.I can print the textbox value in a variable '$experience'.but i cant check it is blank or not.controler name Sitecontroller.php,view search.php and model job.php
My controller is Sitecontroller.php
<?php
class SiteController extends Controller
{
public function actionsearch()
{
$user_id = trim($_GET['id']);
$model = new Job ;
if(isset($_POST['Job']))
{
if(Yii::app()->getRequest()->getIsAjaxRequest())
{
echo CActiveForm::validate(array($jobProfileM2));
Yii::app()->end();
}
$model->attributes=$_POST['Job'];
if($model->validate())
{
$title=$_POST['Job']['title'];
$experience=$_POST['Job']['experience'];
echo "data".$experience=trim($experience);
if($_POST['Job']['experience'] == " ")
{
echo "hai";
}
$model=Job::model()->findAll(array('select'=>'*',"condition"=>"(title like '%$title%')
or (key_skills like '%$title%')",));
$number=count($model);
//$this->redirect($this->createUrl('site/search_result',array('title'=>$title,)));
}
else
{
Yii::app()->user->setFlash('error', "Validation failed!");
}
}
$this->render('search',array('model' =>$model));
}
}
?>
//view-search.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>false,
'htmlOptions' => array(),
'clientOptions'=>array(
'validateOnSubmit'=>true
),
)); ?>
<?php
foreach(Yii::app()->user->getFlashes() as $key => $message) {
echo '<div class="flash-' . $key . '">' . $message . "</div>
";
}
?>
<div class="row">
<?php echo $form->labelEx($model,'Keyword'); ?>
<?php echo $form->textField($model,'title'); ?>
<?php echo $form->error($model,'Keyword'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Experience'); ?>
<?php echo $form->textField($model,'experience'); ?>
<?php echo $form->error($model,'experience'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div>
I cant print 'hai' message when experince textbox is blank.Anybody help me?