neel
(Kazi Neel)
February 19, 2010, 2:54pm
1
Hello,
In my view file i define static check box, my question is, when I put condition in controller, it’s not respond.
view file
<?php echo CHtml::activeLabel($form,‘test’); ?>
<?php echo CHtml::checkBox($form->test); ?>
I need this condition in my controller
if ($form->test){ //if checkbox checked then
$this->redirect(array(‘test1’));
} else {
$this->redirect(array(‘index’));
}
but check box value is not working .
Hello,
In my view file i define static check box, my question is, when I put condition in controller, it’s not respond.
view file
<?php echo CHtml::activeLabel($form,‘test’); ?>
<?php echo CHtml::checkBox($form->test); ?>
I need this condition in my controller
if ($form->test){ //if checkbox checked then
$this->redirect(array(‘test1’));
} else {
$this->redirect(array(‘index’));
}
but check box value is not working .
test is defined in the model?
class ExampleForm extends CFormModel
{
public $test;
...
(in 1.1 declare safe the field)
public function rules()
{
return array(
array('test', 'safe'),
try
$form=new ExampleForm;
if(isset($_POST['ExampleForm'])) {
$form->attributes=$_POST['ExampleForm'];
var_dump($form);
}
mmm
change
<?php echo CHtml::checkBox($form->test); ?>
for
<?php echo CHtml::activeCheckBoxx($form,'test'); ?>
neel
(Kazi Neel)
February 20, 2010, 1:57am
4
test is defined in the model?
class ExampleForm extends CFormModel
{
public $test;
...
(in 1.1 declare safe the field)
public function rules()
{
return array(
array('test', 'safe'),
try
$form=new ExampleForm;
if(isset($_POST['ExampleForm'])) {
$form->attributes=$_POST['ExampleForm'];
var_dump($form);
}
Yes, I already declare in the model. but condition is not working.
this is my controller
if ($form->test){ //if checkbox checked then
$this->redirect(array(‘test1’));
} else {
$this->redirect(array(‘index’));
}
neel
(Kazi Neel)
February 22, 2010, 3:17pm
5
Hello,
I have a static checkbox like this
<div class="simple">
<?php echo CHtml::activeLabel($form,‘test’); ?>
<?php echo CHtml::activeCheckBox($form,‘test’); ?>
</div>
and in my CActiveRecord form , I declare public $test;
and in controller
public function actionIndex()
{
$form=new Test;
if(isset($_POST['Test']))
{
$form->attributes=$_POST['Test'];
if($form->validate())
{
if(isset($_POST[$form->test]) &&
$_POST[$form->test] == 'Yes')
{
$this->redirect(array('index'));
}
else
{
$this->redirect(array('test1'));
}
}
}
$this->render('index',array('form'=>$form));
}
This is not working. Have any idea.
try
public function actionIndex()
{
$form=new Test;
if(isset($_POST['Test']))
{
$form->attributes=$_POST['Test'];
if($form->validate())
if($form->test==1)$this->redirect(array('index'));
elseif ($form->test==0) $this->redirect(array('test1'));
else throw new CHttpException(400,'test is not set');
}
}
neel
(Kazi Neel)
February 22, 2010, 5:34pm
7
it’s not redirecting to test1 page if checkbox value is 0. .
public function actionIndex()
{
$form=new Test;
if(isset($_POST['Test']))
{
$form->attributes=$_POST['Test'];
if($form->validate())
{
if($form->test==1) $this->redirect(array('index'));
elseif ($form->test==0) $this->redirect(array('test1'));
else throw new CHttpException(400,'test is not set');
//var_dump($form);
}
}
$this->render('index',array('form'=>$form));
}
tri
(tri - Tommy Riboe)
February 22, 2010, 5:53pm
8
For massive assignment of attributes to work, in 1.0 you have to declare ‘test’ in safeAttributes(). As already mentioned, in 1.1 you declare it in rules(). If you don’t, ‘test’ will not be massively assigned. Of course, for a single attribute, you can call setAttribute(attribute, value) or just assign to the attribute name directly.
If ‘test’ doesnt get assigned nothing gets validated. I think what you see is the same page being re-rendered (no redirection whatsoever).
/Tommy
neel
(Kazi Neel)
February 22, 2010, 6:24pm
9
tri:
For massive assignment of attributes to work, in 1.0 you have to declare ‘test’ in safeAttributes(). As already mentioned, in 1.1 you declare it in rules(). If you don’t, ‘test’ will not be massively assigned. Of course, for a single attribute, you can call setAttribute(attribute, value) or just assign to the attribute name directly.
If ‘test’ doesnt get assigned nothing gets validated. I think what you see is the same page being re-rendered (no redirection whatsoever).
/Tommy
Hi Tommy,
Can you send me an example, that will help me to understand where is my problem.