How do I use errorSummary in my view, if the form is built using formBuilder?
I tried
echo $form -> errorSummary();
but it doesn't work.
Can it actually be used with formBuilder?
EDIT:
The form:
return array(
'activeForm' => array(
'class' => 'CActiveForm',
'id' => 'nameserver-form',
'enableClientValidation' => true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
),
'showErrorSummary'=>true,
'showErrors'=>true,
'elements'=>array(
'ip1_address'=>array(
'type'=>'dropdownlist',
'empty'=>''
),
'ns1_nameserver'=>array(
'type'=>'text',
'maxlength'=>255,
'size'=>25
)
)
);
this function required a parameter that is not provided in your code.like :
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'user-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'focus'=>array($model,'firstName'),
)); ?>
<?php echo $form->errorSummary($model); ?>
http://www.yiiframework.com/doc/api/1.1/CActiveForm#errorSummary-detail
So, the answer was:
<?= $form->renderBegin(); ?>
...
<?= $form->activeFormWidget->errorSummary($form->getModel(false)); ?>
...
<?= $form->renderEnd(); ?>
Related
how to put link in the classcode to proceed to another form
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'classlist-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
**'classCode'**,
'classDesc',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
You can use a clink column
'columns'=>array(
.....
array(
'class'=>'CLinkColumn',
'label'=>'your_attribute',
'url'=>'your_controller/your_action&id='.$model->your_attribute,
'header'=>'your_column_header'
),
Hii you can also use this
array(
'name' => 'you_field',
'header' => 'label',
'type' => 'raw',
'value' => 'CHtml::link($data->you_field,Yii::app()->createUrl("controller/action",array("param"=>$data->you_field)),array("target"=>"_blank"))',
),
Hi use this code,
array(
'header' =>Your Header Name,
'value' => '$data->subject->subject_name." - ".$data->subject->subject_code',
'url' => 'Yii::app()->createUrl("core/subject/deleteelective", array("id"=>$data->electivesubjectid))',
'htmlOptions' => array('width' => '45%'),
),
I have already added data using select2 yiibooster widget but how i can update data using select2 widget.
how i show already added records in yiibooster select2 widget
<?php
echo $form->labelEx($model, 'measurement');
$this->widget(
'bootstrap.widgets.TbSelect2', array(
'name' => 'measures[]',
'data' => Ingredient::getmeasurementhere(),
'htmlOptions' => array(
'multiple' => 'multiple',
'class' => 'span3',
'id' => 'select1li_id'
),
//'events' => array('change' => 'js:getsubcategories')
)
);
?>
i am getting data using Ingredient::getmeasurementhere() function how i fetch this using update or write new function but how to show in select2 ?
Thanks in advance
I'm using the yii-user extension version 0.3, while trying to customize my registration form, i get this error
Property "RegistrationForm.firstname" is not defined.
below is my code. any idea why?
<?php echo $form->textField($model,'email', array('class' => 'input-block-level', 'placeholder' => 'Email')); ?>
<?php echo $form->passwordField($model,'password', array('class' => 'input-block-level', 'placeholder' => 'Password')); ?>
<?php echo $form->passwordField($model,'verifyPassword', array('class' => 'input-block-level', 'placeholder' => 'Retype Password')); ?>
<?php echo $form->textField($model,'firstname', array('class' => 'input-block-level', 'placeholder' => 'First Name')); ?>
<?php echo $form->textField($model,'lastname', array('class' => 'input-block-level', 'placeholder' => 'Last Name')); ?>
also how would i use the yii language to populate this? so i don't have to hard code it?
'placeholder' => 'E-mail'
basically email would be output as E-mail
From what I see, the $model you've used in your code is an object of "RegistrationForm" Model and the error says that there is no property firstname defined in your RegistrationForm Model.
See if you have spelled it correctly.
To use the the attribute label as Placeholder, I think you need to Extend the CInputWidget
and customize it according to your requirements.
Reference
I'm using cakephp 2.1, where I'm trying to change the password of an user through a link which the user will receive when a forgot password request is make.
The link looks something like this
../myApp/users/change_password/1
I'm passing the user id in the link. i.e, 1 as in above.
The view i.e, change_password.ctp is as below
<?php echo $this->Form->create('User', array('controller' => 'users', 'action' => 'change_password', 'class' => 'well')); ?>
<?php echo $this->Form->input('User.id',array('value' => $this->params['pass'][0],'type'=>'hidden')); ?>
<?php echo $this->Form->label('password', 'Password', array('class' => 'control-label')); ?>
<?php echo $this->Form->password('password', array('class' => 'span3', 'type' => 'password')); ?>
<?php echo $this->Form->error('password', null , array('wrap' => 'span', 'class' => 'help-inline')); ?>
<?php echo $this->Form->submit('Change Password', array('class' => 'btn')); ?>
<?php echo $this->Form->end(); ?>
And the controller is as follows
public function change_password() {
if($this->request->is('post')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash('Password has been changed.', 'default/flash_success');
$this->redirect(array('controller' => 'movies', 'action' => 'index'));
} else {
$this->Session->setFlash('Password could not be changed.', 'default/flash_error');
$this->redirect(array('controller' => 'movies', 'action' => 'index'));
}
}
}
But I'm not able to save the password.
So if i just change the user id in the url, i can change the password of an other user?
/myApp/users/change_password/2
That is not secure at all. You should reconsider an other approach.
However, the answer for your question is:
You are probably not able to change the password because the data is not validated.
Do you have setup validation rules in the User.php model? If yes, you must unset the validation rules before saving the User.
Example: unset($this->User->validate['username']);
For more information about model validation, read the documentation
Is there any way to hide "Summary" for CListView without loosing pagination. By summary i mean text like "Displaying 1-2 of 2 result(s).". Or maybe I should use different widget?
Try the following to get more control over the look of your CListView output:
'template'=>'{items} {pager}'
You can even use HTML in the template.
Ok, I didn't get it at first, when looking into CListView code, but setting 'summaryText' to '' will do the work. I've realised that second time when I was staring at $summaryText === null
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'summaryText'=>'',
'itemView'=>'_indexview',
));
Here is the example for CListView:
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view',
'ajaxUpdate' => false,
'emptyText' => 'No records found.',
'summaryText' => "{start} - {end} из {count}",
'template' => '{summary} {sorter} {items} {pager}',
'sorterHeader' => 'Sort by:',
'sortableAttributes' => array('title', 'price'),
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
'cssFile' => '/css/pager.css',
'htmlOptions' => array('class' => 'pager'),
'maxButtonCount' => '10',
'prevPageLabel'=>'←',
'nextPageLabel'=>'→',
'header'=>'Pages: ',
),
));
You should try this:
'summaryText' => FALSE,
You may hide it by adding CSS in the page like below.
<style>
.summary{
display:none;
}
</style>
Here is my suggestion
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $best_seller_data,
'itemView' => 'alsoBestseller',
'summaryText'=>false,
));