Yii CActiveForm CheckBox not displayed correctly - yii

I'm new using Yii framework. I show a list a checkbox. But it's not displayed correctly.
Here is what I want: http://imageshack.us/photo/my-images/703/checkboxgood.png
But, here is what I get: http://imageshack.us/photo/my-images/715/checkbox.png
Anyway, here is code I used to generate this view:
<div class="row">
<?php echo $form->labelEx($model,'kat3'); ?>
<?php echo $form->checkBox($model,'kat3'); ?>
?php echo $form->error($model,'kat3'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'kat4'); ?>
<?php echo $form->checkBox($model,'kat4'); ?>
<?php echo $form->error($model,'kat4'); ?>
</div>
I am new to web developing, and understand CSS a bit.
Anyone have a suggestion?
thanks! :)

Yii comes with default CSS classes, and that's what you see.
In order to customize these, you must implement your own custom CSS classes for this section. You may wrap your form into a form-class of yours and define the CSS rules as you wish.

Related

slick carousel - two rows for specific columns

I'm using slick carousel and I'm faced with the problem of having multiple rows only on specific columns. Is it possible to do this with slick carousel?
I'm trying to replicate this carousel layout:
As we can see from the image above, this carousel's first and last images are straightforward. However, when we look at the second and third carousel items, we can see these images are in multiple rows.
I understand that slick carousel has a rows function such as this example, but is it possible to only have this feature only for specific columns? If not, would you guys know any other way to accomplish this task?
For context, I'm using the ACF Gallery field (WordPress) to put in the images and using its loop to parse out the images in the front-end like this:
<div class="gallery-carousel">
<?php $index = 1; ?>
<?php foreach( $images as $image ): ?>
<div>
<img
src="<?php echo esc_url($image['url']); ?>"
alt="<?php echo esc_attr($image['alt']); ?>"
/>
<?php echo $index; ?>
</div>
<?php $index++; ?>
<?php endforeach; ?>
</div>
Thank you for your help!

how to add class inside checkbox and label field

i want to implement this html code into yii format.
<input type="checkbox" name="" class="checkbox1" onclick="" id=""/>
<label class="gender" for="" id="">Female</label>
i tried to implement this code.
$form->checkBox($model,'gender',array('class'=>'gen'),array('template'=>'{label}')
but i don't know how to assign gender css class to label field? could please suggest me how to implement above html code in right way.
Please refer this Different Checkbox Properties. you will get answer from there...
if you want to use Chtml::checkBox...
<?php
echo CHtml::checkBox('gender',
array(''),array('class'=>'checkbox1')); ?>
<label style="width:150px;"class="gender">
<?php echo 'Gender' ;?>
</label>
if you want to use $form->checkBox...
<?php
echo $form->checkBox($model,'gender', array('class'=>'checkbox1'));
?>
<label style="width:150px;"class="gender">
<?php echo 'Gender';?>
</label>
Try it's working i have tried in my form...
CHtml::checkBox() gives you only the input tag
To create a <label> you should use CHtml::label() method. There you can set class property for this tag.
Edited:
I do this:
<?php echo $form->checkBox($model, 'gender', array('class'=>'checkbox1')); ?>
<?php echo $form->labelEx($model,'gender', array('class'=>'genger')); ?>
You just can add labelOptions array value to control label:
echo $form->checkBoxList(
$model,
'attr',
array('ggg','hhh'),
'htmlOptions' => array(
'labelOptions' => array(
//put here what you want
)
)
);

Yii - Error 400 The CSRF token could not be verified

I have a very strange problem. I have a login form in Yii which works fine. After moving the website to another server I get
Error 400 The CSRF token could not be verified
I don't understand why it is working on the development server but not on the new server. here is my code:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username'); ?>
<?php echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password'); ?>
<?php echo $form->error($model,'password'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
and here is the csrf configuration in my config file:
'enableCsrfValidation' => !isset($_POST['dontvalidate']) ? true : false,
if you need to see the example. Here is the one which is working, and here is the one with the problem
I opened the first example and found this html in source, This is correct.
<input type="hidden" value="df5a0fc9ab86f85cdcdabe6b2ee62e85d3ac0323"
name="YII_CSRF_TOKEN" />
on the second example page, I haven't found any html code as above. That means enableCsrfValidation is set to false in second example.
try debugging $_POST['dontvalidate'] in this page (or in config/main.php ).

Yii framework, uploading files doesn't work

I have a form and I want to upload a file. here is my code:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'show-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
<fieldset>
<legend>DATI TECNICI</legend>
<div class="row">
<?php echo $form->labelEx($model,'tec_data_file'); ?>
<?php echo $form->fileField($model,'tec_data_file',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'tec_data_file'); ?>
</div>
</fieldset>
<?php $this->endWidget(); ?>
</div><!-- form -->
There was nothing added to the database after submitting, I did a bit of debuging with firebug and figured out that filefield generates a code like this:
<input id="ytShow_tec_data_file" type="hidden" name="Show[tec_data_file]" value="">
<input id="Show_tec_data_file" type="file" name="Show[tec_data_file]" maxlength="45" size="45">
and two data are sent by $_POST for tec_data_file (which is my file field in db). The first var is empty (I think it is related to first hidden input). and the second one contains my file. and when I'm assigning the variables to my model for saving:
$modelPhoto->attributes = $_POST['Photo'];
the tec_data_file gets an empty string! So nothing gets uploaded to my db. Anyone have an idea how to solve this? If you need more i
You need something like:
$model = new Photo;
$model->attributes = $_POST['Photo'];
$model->image = CUploadedFile::getInstance($model,'file');
where file is the name of the field.
I haven't tested this, it's from the documentation.

Yii Many_Many Relationship and Form

// Post model
return array(
'categories' => array(self::MANY_MANY, 'Category', 'categories_posts(post_id, category_id)')
);
I already have the setup of tables
posts
id, title, content
categories
id, name
categories_posts
post_id, category_i
The problem I have is that I am getting an error when creating this form:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'post-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'title'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'uri'); ?>
<?php echo $form->textField($model,'uri',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'uri'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'content'); ?>
<?php echo $form->textArea($model,'content',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'content'); ?>
</div>
<div class="row">
<?php // echo $form->labelEx($model,'content'); ?>
<?php echo CHtml::activeDropDownList($model,'category_id', CHtml::listData(Category::model()->findAll(), 'id', 'name')); ?>
<?php // echo $form->error($model,'content'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
The error is:
Property "Post.category_id" is not defined.
I am quite confused. What should I be doing to correct this?
I use the CAdvancedArBehavior to make this easier. I wouldn't be surprised if something like this gets rolled into the Yii core eventually either:
http://www.yiiframework.com/extension/cadvancedarbehavior/
It lets you write code like this in your controller:
$model->categories = $_POST['Post']['categories'];
I use this with the more-bugggy-than-I-would-like "Relation" widget/extension. You might need to use that to get the POST variables to structure correctly, I'm not sure.
I honestly thought that Yii has something like Kohana or Cake in their AR anyway. I guess I have to manually add them.
foreach ($_POST['category_id'] as $category_id)
{
$categoryPost = new CategoryPost;
$categoryPost->category_id = $category_id;
$categoryPost->post_id = $model->id;
$categoryPost->save();
}
Use in this way:
In controller
create object for category: $modelCat= new Category;
then in
<?php echo CHtml::activeDropDownList(**$modelCat**,'category_id', CHtml::listData(Category::model()->findAll(), 'id', 'name')); ?>