Hi all,
I am fairly new to YII and I was hoping to get some help figuring out why my site controller is not detecting a post that is being processed in the view. I inserted
if($_POST)
echo "it works"
in the view and that does echo once the submit button is pressed. Any thoughts?
siteController code (siteController.php)
public function actionIntermediatelogin()
{
$model = new IntermediateLoginForm;
if(isset($_POST['IntermediateLoginForm']))
{
if($model->validate())
{
$this->layout = "SROMain";
$this->render('SROindex');
}
}
}
my form model (IntermediateLoginForm.php)
class IntermediateLoginForm extends CFormModel
{
public $continue;
public $role;
public $relationship;
public function rules()
{
return array(
array('role, relationship', 'required'),
);
}
/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'continue'=>'continue',
);
}
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->addError('relationship','You must select a role and relationship to continue');
}
}
}
my view (IntermediateLogin.php)
<div class="form">
<?php $form=$this->beginWidget(‘CActiveForm’, array(
'id'=>'IntermediateLoginForm-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<h1>Welcome Person </h1>
<h1>This is an intermediate login page</h1>
<? //allow the user to select their role ?>
<p>select your role</p>
<select name="roles" size="1">
<option>Choose a role</option>
<option>role1</option>
<option>role2</option>
</select>
<br/><br/>
<p>Select Relationship</p>
<select name="relationshipName" size="1">
<option>Choose a relationship</option>
<option>relat1</option>
<option>relat2</option>
</select>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
<?php
if($_POST)
{
echo "it works";
}
?>